@akanjs/devkit 3.3.0-rc.3 → 3.3.0-rc.31
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 +547 -0
- package/DEV_RUNTIME_KNOBS.md +1 -1
- package/README.ko.md +3 -2
- package/README.md +3 -3
- package/akanApp/akanApp.host.test.ts +1 -1
- package/akanApp/akanApp.host.ts +11 -0
- package/akanConfig/akanBin.ts +4 -0
- package/akanConfig/akanConfig.test.ts +66 -7
- package/akanConfig/akanConfig.ts +53 -204
- package/akanConfig/akanWorkers.test.ts +39 -0
- package/akanConfig/akanWorkers.ts +32 -0
- package/akanConfig/desktopServerConfig.ts +96 -0
- package/akanConfig/dockerImage.ts +37 -0
- package/akanConfig/nativeKeys.ts +52 -0
- package/akanConfig/types.ts +1 -0
- package/app/appBin.test.ts +63 -0
- package/app/appBin.ts +50 -0
- package/app/applicationBuildReporter.test.ts +32 -0
- package/app/applicationBuildReporter.ts +4 -0
- package/app/applicationBuildRunner.test.ts +275 -0
- package/app/applicationBuildRunner.ts +126 -5
- package/app/dictionarySizes.ts +94 -0
- 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 +60 -8
- package/biome.base.json +5 -1
- 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-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 +4 -14
- package/codeAgent/skills/akan-query/SKILL.md +13 -20
- package/codeAgent/skills/akan-runtime/SKILL.md +20 -0
- package/codeAgent/skills/akan-service/SKILL.md +2 -5
- package/codeAgent/skills/akan-transport/SKILL.md +5 -14
- package/codeAgent/skills/akan-ui/SKILL.md +2 -5
- package/context/akanContext.ts +2 -0
- package/docs/apiReference.test.ts +9 -0
- package/docs/apiReference.ts +14 -0
- package/executors/clientRuntimeKeyOrder.fixture.json +682 -0
- package/executors/clientRuntimeKeys.fixture.json +393 -0
- package/executors/clientRuntimeKeys.test.ts +1591 -0
- package/executors/executors.test.ts +2 -0
- package/executors/sysExecutor.ts +66 -3
- package/executors/workspaceExecutor.ts +7 -4
- package/frontendBuild/allRoutesBuilder.ts +72 -3
- package/frontendBuild/autoImportSync.ts +3 -2
- package/frontendBuild/buildRouteClient.test.ts +515 -12
- package/frontendBuild/clientBuildTypes.ts +15 -0
- package/frontendBuild/clientEntriesBundler.ts +38 -0
- package/frontendBuild/clientEntryDiscovery.test.ts +95 -1
- package/frontendBuild/clientEntryDiscovery.ts +88 -7
- package/frontendBuild/csrDevModuleCompiler.test.ts +86 -0
- package/frontendBuild/csrDevModuleCompiler.ts +44 -8
- package/frontendBuild/csrDevPatcher.ts +33 -7
- package/frontendBuild/csrDevTypes.ts +9 -0
- package/frontendBuild/devBarrelImports.test.ts +100 -0
- package/frontendBuild/devBarrelImports.ts +82 -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 +316 -0
- package/frontendBuild/dictionaryAssetBuilder.ts +152 -16
- package/frontendBuild/dictionaryConstants.ts +82 -0
- package/frontendBuild/dictionaryPacking.test.ts +84 -0
- package/frontendBuild/dictionaryPacking.ts +92 -0
- package/frontendBuild/dictionaryRoutes.test.ts +186 -0
- package/frontendBuild/dictionaryRoutes.ts +225 -0
- package/frontendBuild/pagesBundleBuilder.test.ts +84 -0
- package/frontendBuild/pagesBundleBuilder.ts +81 -3
- package/frontendBuild/precompressArtifacts.ts +7 -0
- package/frontendBuild/registryMetadataFingerprint.ts +3 -3
- package/frontendBuild/routeClientBuilder.ts +288 -15
- package/frontendBuild/routeHandoffs.test.ts +145 -0
- package/frontendBuild/routeHandoffs.ts +115 -0
- package/frontendBuild/routeRuntimeCheck.test.ts +257 -0
- package/frontendBuild/routeRuntimeCheck.ts +241 -0
- package/frontendBuild/routeRuntimePays.test.ts +137 -0
- package/frontendBuild/routeRuntimePays.ts +117 -0
- package/frontendBuild/rscServerRendererGuard.test.ts +60 -0
- package/frontendBuild/rscServerRendererGuard.ts +68 -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/biomeCheck.test.ts +145 -0
- package/lint/biomeCheck.ts +131 -0
- 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.ts +1 -0
- 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/serverBundleSecrets.ts +43 -0
- package/package.json +15 -169
- package/packageExports.test.ts +38 -24
- package/quality/dictionaryKeys.test.ts +173 -0
- package/quality/dictionaryKeys.ts +415 -0
- package/quality/objectImportReport.test.ts +36 -0
- package/quality/objectImportReport.ts +102 -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/test/secretEnvFixture.ts +134 -0
- package/test/testHelpers.ts +11 -0
- package/transforms/barrelAnalyzer.ts +26 -4
- package/transforms/barrelImportsPlugin.ts +82 -14
- 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/objectImportEdits.ts +150 -0
- package/transforms/objectMemberImports.test.ts +347 -0
- package/transforms/objectMemberImports.ts +537 -0
- package/transforms/objectModule.test.ts +237 -0
- package/transforms/objectModule.ts +458 -0
- package/transforms/objectModuleAnalyzer.ts +104 -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 +115 -2
- package/transforms/serverEnvProfile.ts +117 -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 +18 -11
- package/typecheck/projectTypecheck.test.ts +29 -0
- 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/getRelatedCnsts.ts +7 -0
- package/workspace/scanInfo.ts +1 -1
- package/workspace/workspaceLayout.ts +1 -0
|
@@ -0,0 +1,1591 @@
|
|
|
1
|
+
import { afterAll, describe, expect, spyOn, test } from "bun:test";
|
|
2
|
+
import { mkdir, readdir, realpath, rm, symlink } from "node:fs/promises";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { Logger } from "akanjs/common";
|
|
6
|
+
import { type RuntimeFamily, RuntimeNameTable, runtimeFamilies } from "../quality/runtimeNameTable";
|
|
7
|
+
import { RuntimeUse } from "../quality/runtimeUse";
|
|
8
|
+
import { createTempApp, tempRoots, writeJson, writeText } from "../test/testHelpers";
|
|
9
|
+
import { RouteRuntime } from "../transforms/routeRuntime";
|
|
10
|
+
|
|
11
|
+
const trackRoot = tempRoots();
|
|
12
|
+
const akanjsRoot = path.resolve(import.meta.dir, "../../../akanjs");
|
|
13
|
+
const recordedPath = path.join(import.meta.dir, "clientRuntimeKeys.fixture.json");
|
|
14
|
+
const baseModules = ["agent", "base"];
|
|
15
|
+
const howToRecord =
|
|
16
|
+
"The keys an app's whole client runtime answers no longer match clientRuntimeKeys.fixture.json. If the change is " +
|
|
17
|
+
"intended, record them with AKAN_RECORD_CLIENT_RUNTIME_KEYS=1 bun test --isolate ./executors/clientRuntimeKeys.test.ts " +
|
|
18
|
+
"and review the fixture's diff.";
|
|
19
|
+
|
|
20
|
+
const option = `import { AkanOption } from "akanjs/server";
|
|
21
|
+
import type { LibOptions } from "./srv";
|
|
22
|
+
|
|
23
|
+
export type ModulesOptions = LibOptions & { [key: string]: unknown };
|
|
24
|
+
|
|
25
|
+
export const option = new AkanOption<ModulesOptions>();
|
|
26
|
+
`;
|
|
27
|
+
|
|
28
|
+
const kitFiles: Record<string, string> = {
|
|
29
|
+
"common/kitLabel.ts": 'export const kitLabel = "kit";\n',
|
|
30
|
+
"lib/option.ts": option,
|
|
31
|
+
"lib/item/item.constant.ts": `import { via } from "akanjs/constant";
|
|
32
|
+
|
|
33
|
+
export class ItemInput extends via((field) => ({
|
|
34
|
+
name: field(String),
|
|
35
|
+
})) {}
|
|
36
|
+
|
|
37
|
+
export class ItemObject extends via(ItemInput, (field) => ({})) {}
|
|
38
|
+
|
|
39
|
+
export class LightItem extends via(ItemObject, ["name"] as const, (resolve) => ({})) {}
|
|
40
|
+
|
|
41
|
+
export class Item extends via(ItemObject, LightItem, (resolve) => ({})) {}
|
|
42
|
+
|
|
43
|
+
export class ItemInsight extends via(Item, (field) => ({})) {}
|
|
44
|
+
`,
|
|
45
|
+
"lib/item/item.dictionary.ts": `import { modelDictionary } from "akanjs/dictionary";
|
|
46
|
+
|
|
47
|
+
import type { Item, ItemInsight } from "./item.constant";
|
|
48
|
+
import type { ItemFilter } from "./item.document";
|
|
49
|
+
import type { ItemEndpoint, ItemSlice } from "./item.signal";
|
|
50
|
+
|
|
51
|
+
export const dictionary = modelDictionary(["en", "ko"])
|
|
52
|
+
.of((t) => t(["Item", "아이템"]).desc(["Something listed", "목록의 항목"]))
|
|
53
|
+
.model<Item>((t) => ({
|
|
54
|
+
name: t(["Name", "이름"]).desc(["What the item is called", "항목 이름"]),
|
|
55
|
+
}))
|
|
56
|
+
.insight<ItemInsight>((t) => ({}))
|
|
57
|
+
.query<ItemFilter>((fn) => ({}))
|
|
58
|
+
.sort<ItemFilter>((t) => ({}))
|
|
59
|
+
.slice<ItemSlice>((fn) => ({
|
|
60
|
+
inPublic: fn(["Item In Public", "공개 항목"]).desc(["Every item", "모든 항목"]).arg((t) => ({})),
|
|
61
|
+
}))
|
|
62
|
+
.endpoint<ItemEndpoint>((fn) => ({
|
|
63
|
+
itemCount: fn(["Item Count", "항목 수"]).desc(["How many items there are", "항목 수"]),
|
|
64
|
+
}))
|
|
65
|
+
.translate({});
|
|
66
|
+
`,
|
|
67
|
+
"lib/item/item.document.ts": `import { by, from, into } from "akanjs/document";
|
|
68
|
+
|
|
69
|
+
import * as cnst from "../cnst";
|
|
70
|
+
|
|
71
|
+
export class ItemFilter extends from(cnst.Item, (filter) => ({ query: {}, sort: {} })) {}
|
|
72
|
+
|
|
73
|
+
export class Item extends by(cnst.Item) {}
|
|
74
|
+
|
|
75
|
+
export class ItemModel extends into(Item, ItemFilter, cnst.item, () => ({})) {}
|
|
76
|
+
`,
|
|
77
|
+
"lib/item/item.service.ts": `import { serve } from "akanjs/service";
|
|
78
|
+
|
|
79
|
+
import * as db from "../db";
|
|
80
|
+
|
|
81
|
+
export class ItemService extends serve(db.item, () => ({})) {}
|
|
82
|
+
`,
|
|
83
|
+
"lib/item/item.signal.ts": `import { Int } from "akanjs/base";
|
|
84
|
+
import { endpoint, internal, Public, slice } from "akanjs/signal";
|
|
85
|
+
|
|
86
|
+
import * as srv from "../srv";
|
|
87
|
+
|
|
88
|
+
export class ItemInternal extends internal(srv.item, () => ({})) {}
|
|
89
|
+
|
|
90
|
+
export class ItemSlice extends slice(
|
|
91
|
+
srv.item,
|
|
92
|
+
{ guards: { root: Public, get: Public, cru: Public }, mcp: false },
|
|
93
|
+
(init) => ({
|
|
94
|
+
inPublic: init({ guards: [Public], mcp: false }).exec(function () {
|
|
95
|
+
return this.itemService.queryAny();
|
|
96
|
+
}),
|
|
97
|
+
}),
|
|
98
|
+
) {}
|
|
99
|
+
|
|
100
|
+
export class ItemEndpoint extends endpoint(srv.item, ({ query }) => ({
|
|
101
|
+
itemCount: query(Int, { guards: [Public], mcp: false }).exec(() => 0),
|
|
102
|
+
})) {}
|
|
103
|
+
`,
|
|
104
|
+
"lib/item/item.store.ts": `import { store } from "akanjs/store";
|
|
105
|
+
|
|
106
|
+
import { fetch, sig } from "../useClient";
|
|
107
|
+
|
|
108
|
+
export class ItemStore extends store(sig.item, () => ({ itemCount: 0 })) {
|
|
109
|
+
async refreshItemCount() {
|
|
110
|
+
this.set({ itemCount: await fetch.itemCount() });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
`,
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const demoFiles: Record<string, string> = {
|
|
117
|
+
"lib/option.ts": option,
|
|
118
|
+
"lib/item/item.constant.ts": `import { via } from "akanjs/constant";
|
|
119
|
+
|
|
120
|
+
import { item } from "../__lib/lib.constant";
|
|
121
|
+
|
|
122
|
+
export class ItemInput extends via((field) => ({}), ...item.inputs) {}
|
|
123
|
+
|
|
124
|
+
export class ItemObject extends via(ItemInput, (field) => ({ note: field(String, { default: "" }) }), ...item.objects) {}
|
|
125
|
+
|
|
126
|
+
export class LightItem extends via(ItemObject, ["note"] as const, (resolve) => ({}), ...item.lights) {}
|
|
127
|
+
|
|
128
|
+
export class Item extends via(ItemObject, LightItem, (resolve) => ({}), ...item.models) {}
|
|
129
|
+
|
|
130
|
+
export class ItemInsight extends via(Item, (field) => ({}), ...item.insights) {}
|
|
131
|
+
`,
|
|
132
|
+
"lib/item/item.dictionary.ts": `import { modelDictionary } from "akanjs/dictionary";
|
|
133
|
+
|
|
134
|
+
import { item } from "../__lib/lib.dictionary";
|
|
135
|
+
import type { Item } from "./item.constant";
|
|
136
|
+
import type { ItemEndpoint, ItemSlice } from "./item.signal";
|
|
137
|
+
|
|
138
|
+
export const dictionary = modelDictionary(["en", "ko"], ...item.dictionaries)
|
|
139
|
+
.model<Item>((t) => ({
|
|
140
|
+
note: t(["Note", "메모"]).desc(["What the app adds to an item", "앱이 항목에 덧붙이는 메모"]),
|
|
141
|
+
}))
|
|
142
|
+
.slice<ItemSlice>((fn) => ({
|
|
143
|
+
withNote: fn(["Item With Note", "메모가 있는 항목"]).desc(["Items with a note", "메모가 있는 항목"]).arg((t) => ({})),
|
|
144
|
+
}))
|
|
145
|
+
.endpoint<ItemEndpoint>((fn) => ({
|
|
146
|
+
itemNote: fn(["Item Note", "항목 메모"]).desc(["The note of the latest item", "최근 항목의 메모"]),
|
|
147
|
+
}))
|
|
148
|
+
.translate({});
|
|
149
|
+
`,
|
|
150
|
+
"lib/item/item.document.ts": `import { by, from, into } from "akanjs/document";
|
|
151
|
+
|
|
152
|
+
import { item } from "../__lib/lib.document";
|
|
153
|
+
import * as cnst from "../cnst";
|
|
154
|
+
|
|
155
|
+
export class ItemFilter extends from(cnst.Item, (filter) => ({ query: {}, sort: {} }), ...item.filters) {}
|
|
156
|
+
|
|
157
|
+
export class Item extends by(cnst.Item, ...item.docs) {}
|
|
158
|
+
|
|
159
|
+
export class ItemModel extends into(Item, ItemFilter, cnst.item, () => ({}), ...item.models) {}
|
|
160
|
+
`,
|
|
161
|
+
"lib/item/item.service.ts": `import { serve } from "akanjs/service";
|
|
162
|
+
|
|
163
|
+
import { item } from "../__lib/lib.service";
|
|
164
|
+
import * as db from "../db";
|
|
165
|
+
|
|
166
|
+
export class ItemService extends serve(db.item, () => ({}), ...item.services) {}
|
|
167
|
+
`,
|
|
168
|
+
"lib/item/item.signal.ts": `import { endpoint, internal, Public, slice } from "akanjs/signal";
|
|
169
|
+
|
|
170
|
+
import { item } from "../__lib/lib.signal";
|
|
171
|
+
import * as srv from "../srv";
|
|
172
|
+
|
|
173
|
+
export class ItemInternal extends internal(srv.item, () => ({}), ...item.internals) {}
|
|
174
|
+
|
|
175
|
+
export class ItemSlice extends slice(
|
|
176
|
+
srv.item,
|
|
177
|
+
{ guards: { root: Public, get: Public, cru: Public }, mcp: false },
|
|
178
|
+
(init) => ({
|
|
179
|
+
withNote: init({ guards: [Public], mcp: false }).exec(function () {
|
|
180
|
+
return this.itemService.queryAny();
|
|
181
|
+
}),
|
|
182
|
+
}),
|
|
183
|
+
...item.slices,
|
|
184
|
+
) {}
|
|
185
|
+
|
|
186
|
+
export class ItemEndpoint extends endpoint(
|
|
187
|
+
srv.item,
|
|
188
|
+
({ query }) => ({
|
|
189
|
+
itemNote: query(String, { guards: [Public], mcp: false }).exec(() => ""),
|
|
190
|
+
}),
|
|
191
|
+
...item.endpoints,
|
|
192
|
+
) {}
|
|
193
|
+
`,
|
|
194
|
+
"lib/item/item.store.ts": `import { store } from "akanjs/store";
|
|
195
|
+
|
|
196
|
+
import { item } from "../__lib/lib.store";
|
|
197
|
+
import { fetch, sig } from "../useClient";
|
|
198
|
+
|
|
199
|
+
export class ItemStore extends store(sig.item, () => ({ noteDraft: "" }), ...item.stores) {
|
|
200
|
+
async loadItemNote() {
|
|
201
|
+
this.set({ noteDraft: await fetch.itemNote() });
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
`,
|
|
205
|
+
"lib/_demo/demo.dictionary.ts": `import { serviceDictionary } from "akanjs/dictionary";
|
|
206
|
+
|
|
207
|
+
import type { DemoEndpoint } from "./demo.signal";
|
|
208
|
+
|
|
209
|
+
export const dictionary = serviceDictionary(["en", "ko"])
|
|
210
|
+
.endpoint<DemoEndpoint>((fn) => ({
|
|
211
|
+
ping: fn(["Ping", "핑"]),
|
|
212
|
+
}))
|
|
213
|
+
.translate({});
|
|
214
|
+
`,
|
|
215
|
+
"lib/_demo/demo.service.ts": `import { serve } from "akanjs/service";
|
|
216
|
+
|
|
217
|
+
export class DemoService extends serve("demo" as const, () => ({})) {}
|
|
218
|
+
`,
|
|
219
|
+
"lib/_demo/demo.signal.ts": `import { endpoint, internal, Public } from "akanjs/signal";
|
|
220
|
+
|
|
221
|
+
import * as srv from "../srv";
|
|
222
|
+
|
|
223
|
+
export class DemoInternal extends internal(srv.demo, () => ({})) {}
|
|
224
|
+
|
|
225
|
+
export class DemoEndpoint extends endpoint(srv.demo, ({ query }) => ({
|
|
226
|
+
ping: query(String, { guards: [Public], mcp: false }).exec(() => "pong"),
|
|
227
|
+
})) {}
|
|
228
|
+
`,
|
|
229
|
+
"lib/_demo/demo.store.ts": `import { kitLabel } from "@libs/kit/common";
|
|
230
|
+
import { store } from "akanjs/store";
|
|
231
|
+
|
|
232
|
+
export class DemoStore extends store("demo" as const, () => ({ label: kitLabel })) {
|
|
233
|
+
pickLabel(label: string) {
|
|
234
|
+
this.set({ label });
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
`,
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
const kitModuleNamed = (name: string, Name: string) =>
|
|
241
|
+
Object.fromEntries(
|
|
242
|
+
Object.entries(kitFiles)
|
|
243
|
+
.filter(([file]) => file.startsWith("lib/item/"))
|
|
244
|
+
.map(([file, content]) => [
|
|
245
|
+
file.replaceAll("item", name),
|
|
246
|
+
content.replaceAll("item", name).replaceAll("Item", Name),
|
|
247
|
+
]),
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
const keysScript = `
|
|
251
|
+
import { FetchClient } from "akanjs/fetch";
|
|
252
|
+
const { fetch, sig } = await import("./apps/demo/lib/useClient.ts");
|
|
253
|
+
const { st } = await import("./apps/demo/lib/st.ts");
|
|
254
|
+
const sorted = (keys) => [...new Set(keys)].sort();
|
|
255
|
+
const serializedSignal = fetch.serializedSignal;
|
|
256
|
+
const handlers = Object.entries(serializedSignal).flatMap(([refName, signal]) =>
|
|
257
|
+
FetchClient.claimsOf(refName, signal).handlers.map(({ key }) => key),
|
|
258
|
+
);
|
|
259
|
+
console.log(JSON.stringify({
|
|
260
|
+
"st.do": sorted(Object.keys(st.do)),
|
|
261
|
+
"st.use": sorted(Object.keys(st.use)),
|
|
262
|
+
"st.slice": sorted(Object.keys(st.slice)),
|
|
263
|
+
"fetch.slice": sorted(Object.keys(fetch.slice)),
|
|
264
|
+
sig: sorted(Object.keys(sig)),
|
|
265
|
+
"fetch.serializedSignal": sorted(Object.keys(serializedSignal)),
|
|
266
|
+
"FetchClient.claimsOf": sorted(handlers),
|
|
267
|
+
}));
|
|
268
|
+
`;
|
|
269
|
+
|
|
270
|
+
const moduleKeysScript = `
|
|
271
|
+
import { FetchClient } from "akanjs/fetch";
|
|
272
|
+
import { StoreInstance, StoreRegistry } from "akanjs/store";
|
|
273
|
+
const { fetch, sig } = await import("./apps/demo/lib/useClient.ts");
|
|
274
|
+
await import("./apps/demo/lib/st.ts");
|
|
275
|
+
const modules = {};
|
|
276
|
+
const add = (refName, family, keys) => ((modules[refName] ??= {})[family] ??= []).push(...keys);
|
|
277
|
+
for (const [refName, store] of StoreRegistry.stores) {
|
|
278
|
+
const own = new StoreInstance(StoreRegistry.merge("own", store));
|
|
279
|
+
for (const family of ["do", "use", "slice"]) add(refName, "st." + family, Object.keys(own[family]));
|
|
280
|
+
}
|
|
281
|
+
for (const [refName, signal] of Object.entries(fetch.serializedSignal))
|
|
282
|
+
add(refName, "fetch", FetchClient.claimsOf(refName, signal).handlers.map(({ key }) => key));
|
|
283
|
+
for (const [key, { refName }] of Object.entries(fetch.slice)) add(refName, "fetch.slice", [key]);
|
|
284
|
+
for (const refName of Object.keys(fetch.serializedSignal)) add(refName, "fetch.serializedSignal", [refName]);
|
|
285
|
+
for (const refName of Object.keys(sig)) add(refName, "sig", [refName]);
|
|
286
|
+
console.log(JSON.stringify(modules));
|
|
287
|
+
`;
|
|
288
|
+
|
|
289
|
+
const browserScript = `
|
|
290
|
+
Object.assign(globalThis, { window: globalThis, location: new URL("http://localhost:4200/") });
|
|
291
|
+
const { FetchClient } = await import("akanjs/fetch");
|
|
292
|
+
const app = await import("./apps/demo/lib/useClient.ts");
|
|
293
|
+
const lib = await import("./libs/kit/lib/useClient.ts");
|
|
294
|
+
const tab = FetchClient.build({}, {}).fetch;
|
|
295
|
+
console.log(JSON.stringify({
|
|
296
|
+
appIsTab: app.fetch === tab,
|
|
297
|
+
libIsTab: lib.fetch === tab,
|
|
298
|
+
"fetch.slice": Object.keys(tab.slice).sort(),
|
|
299
|
+
}));
|
|
300
|
+
`;
|
|
301
|
+
|
|
302
|
+
const pageModuleFiles: Record<string, string> = {
|
|
303
|
+
...kitModuleNamed("page", "Page"),
|
|
304
|
+
"lib/page/Page.Unit.tsx": "export const Card = () => null;\n",
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
const clientBarrelScript = `
|
|
308
|
+
const { Page, st, usePage } = await import("./apps/site/client.ts");
|
|
309
|
+
console.log(JSON.stringify({ unit: typeof Page.Unit.Card, store: typeof st.do.refreshPageCount, usePage: typeof usePage }));
|
|
310
|
+
`;
|
|
311
|
+
|
|
312
|
+
const writeWorkspace = async ({
|
|
313
|
+
app = "demo",
|
|
314
|
+
lib = "kit",
|
|
315
|
+
libFiles = { ...kitFiles, ...kitModuleNamed("tag", "Tag") },
|
|
316
|
+
appFiles = demoFiles,
|
|
317
|
+
kept = false,
|
|
318
|
+
moreLibs = {} as Record<string, Record<string, string>>,
|
|
319
|
+
} = {}) => {
|
|
320
|
+
const created = await createTempApp(app, await realpath(os.tmpdir()));
|
|
321
|
+
const temp = kept ? created : trackRoot(created);
|
|
322
|
+
const { root } = temp;
|
|
323
|
+
await mkdir(path.join(root, "node_modules"), { recursive: true });
|
|
324
|
+
await symlink(akanjsRoot, path.join(root, "node_modules/akanjs"));
|
|
325
|
+
await writeJson(path.join(root, "tsconfig.json"), {
|
|
326
|
+
compilerOptions: { target: "ESNext", paths: { "@apps/*": ["./apps/*"], "@libs/*": ["./libs/*"] } },
|
|
327
|
+
references: [],
|
|
328
|
+
});
|
|
329
|
+
await writeJson(path.join(root, "apps", app, "tsconfig.json"), { extends: "../../tsconfig.json" });
|
|
330
|
+
for (const [name, files] of Object.entries({ [lib]: libFiles, ...moreLibs })) {
|
|
331
|
+
const dir = path.join(root, "libs", name);
|
|
332
|
+
await writeJson(path.join(dir, "tsconfig.json"), { extends: "../../tsconfig.json" });
|
|
333
|
+
await writeJson(path.join(dir, "package.json"), { type: "module", name: `@${name}`, version: "0.0.1" });
|
|
334
|
+
await writeText(path.join(dir, "akan.config.ts"), "export default {};\n");
|
|
335
|
+
await writeText(path.join(dir, "lib/__scalar/.keep"), "");
|
|
336
|
+
for (const [file, content] of Object.entries(files)) await writeText(path.join(dir, file), content);
|
|
337
|
+
}
|
|
338
|
+
for (const [file, content] of Object.entries(appFiles)) await writeText(path.join(root, "apps", app, file), content);
|
|
339
|
+
await temp.app.scan();
|
|
340
|
+
return temp;
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
let demoRoot: Promise<string> | null = null;
|
|
344
|
+
const demoWorkspace = () => {
|
|
345
|
+
demoRoot ??= writeWorkspace({ kept: true }).then(({ root }) => root);
|
|
346
|
+
return demoRoot;
|
|
347
|
+
};
|
|
348
|
+
afterAll(async () => {
|
|
349
|
+
if (demoRoot) await rm(await demoRoot, { recursive: true, force: true });
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
//? The scan caches each app and lib by name for the process, so a second `demo` or `kit` would reuse the first's.
|
|
353
|
+
const writePageWorkspace = async () => {
|
|
354
|
+
const temp = trackRoot(await createTempApp("site", await realpath(os.tmpdir())));
|
|
355
|
+
const { root } = temp;
|
|
356
|
+
await mkdir(path.join(root, "node_modules"), { recursive: true });
|
|
357
|
+
await symlink(akanjsRoot, path.join(root, "node_modules/akanjs"));
|
|
358
|
+
await writeJson(path.join(root, "tsconfig.json"), {
|
|
359
|
+
compilerOptions: { target: "ESNext", paths: { "@apps/*": ["./apps/*"] } },
|
|
360
|
+
references: [],
|
|
361
|
+
});
|
|
362
|
+
await writeJson(path.join(root, "apps/site/tsconfig.json"), { extends: "../../tsconfig.json" });
|
|
363
|
+
for (const [file, content] of Object.entries({ "lib/option.ts": option, ...pageModuleFiles }))
|
|
364
|
+
await writeText(path.join(root, "apps/site", file), content);
|
|
365
|
+
await temp.app.scan();
|
|
366
|
+
return root;
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
const evaluate = async (root: string, script: string, appName = "demo") => {
|
|
370
|
+
const proc = Bun.spawn([process.execPath, "-e", script], {
|
|
371
|
+
cwd: root,
|
|
372
|
+
env: {
|
|
373
|
+
...process.env,
|
|
374
|
+
AKAN_PUBLIC_APP_NAME: appName,
|
|
375
|
+
AKAN_PUBLIC_REPO_NAME: "repo",
|
|
376
|
+
AKAN_PUBLIC_SERVE_DOMAIN: "localhost",
|
|
377
|
+
AKAN_PUBLIC_ENV: "local",
|
|
378
|
+
},
|
|
379
|
+
stdout: "pipe",
|
|
380
|
+
stderr: "pipe",
|
|
381
|
+
});
|
|
382
|
+
const [code, stdout, stderr] = await Promise.all([
|
|
383
|
+
proc.exited,
|
|
384
|
+
new Response(proc.stdout).text(),
|
|
385
|
+
new Response(proc.stderr).text(),
|
|
386
|
+
]);
|
|
387
|
+
if (code !== 0) throw new Error(`the generated runtime did not load:\n${stderr}`);
|
|
388
|
+
return JSON.parse(stdout.trim().split("\n").at(-1) ?? "{}") as Record<string, unknown>;
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
describe("an app's whole client runtime", () => {
|
|
392
|
+
test("answers the same store, fetch and signal keys as recorded, and in a browser shares the tab's one fetch client with its lib", async () => {
|
|
393
|
+
const root = await demoWorkspace();
|
|
394
|
+
const keys = await evaluate(root, keysScript);
|
|
395
|
+
if (process.env.AKAN_RECORD_CLIENT_RUNTIME_KEYS === "1")
|
|
396
|
+
await Bun.write(recordedPath, `${JSON.stringify(keys, null, 2)}\n`);
|
|
397
|
+
expect(keys, howToRecord).toEqual(await Bun.file(recordedPath).json());
|
|
398
|
+
expect(await evaluate(root, browserScript)).toEqual({
|
|
399
|
+
appIsTab: true,
|
|
400
|
+
libIsTab: true,
|
|
401
|
+
"fetch.slice": ["item", "itemInPublic", "itemWithNote", "tag", "tagInPublic"],
|
|
402
|
+
});
|
|
403
|
+
}, 120_000);
|
|
404
|
+
|
|
405
|
+
test("loads from the client barrel when a database module is named page, its UI and store included", async () => {
|
|
406
|
+
const loaded = await evaluate(await writePageWorkspace(), clientBarrelScript, "site");
|
|
407
|
+
expect(loaded).toEqual({ unit: "function", store: "function", usePage: "function" });
|
|
408
|
+
}, 120_000);
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
describe("the client runtime name table", () => {
|
|
412
|
+
test("reads from source every name the whole runtime answers, each owned by the module whose own runtime answers it", async () => {
|
|
413
|
+
const root = await demoWorkspace();
|
|
414
|
+
const table = await RuntimeNameTable.read(root, "apps/demo");
|
|
415
|
+
if (!table) throw new Error("the demo app has no generated client runtime");
|
|
416
|
+
const recorded = (await Bun.file(recordedPath).json()) as Record<string, string[]>;
|
|
417
|
+
expect(Object.fromEntries(runtimeFamilies.map((family) => [family, table.keysOf(family)]))).toEqual(
|
|
418
|
+
Object.fromEntries(
|
|
419
|
+
runtimeFamilies.map((family) => [family, recorded[family === "fetch" ? "FetchClient.claimsOf" : family]]),
|
|
420
|
+
),
|
|
421
|
+
);
|
|
422
|
+
const modules = (await evaluate(root, moduleKeysScript)) as Record<
|
|
423
|
+
string,
|
|
424
|
+
Partial<Record<RuntimeFamily, string[]>>
|
|
425
|
+
>;
|
|
426
|
+
const answeredByBase = (family: RuntimeFamily, key: string) =>
|
|
427
|
+
baseModules.some((module) => modules[module]?.[family]?.includes(key));
|
|
428
|
+
const misses = runtimeFamilies.flatMap((family) => [
|
|
429
|
+
...table.keysOf(family).flatMap((key) => {
|
|
430
|
+
const entry = table.lookup(family, key);
|
|
431
|
+
return [
|
|
432
|
+
...(entry?.base && !answeredByBase(family, key)
|
|
433
|
+
? [`${family}.${key} is a base name no base runtime has`]
|
|
434
|
+
: []),
|
|
435
|
+
...(entry?.owners ?? [])
|
|
436
|
+
.filter(({ module }) => !modules[module]?.[family]?.includes(key))
|
|
437
|
+
.map(({ scope, module }) => `${family}.${key} is owned by ${scope}/${module}, whose own runtime lacks it`),
|
|
438
|
+
];
|
|
439
|
+
}),
|
|
440
|
+
...Object.entries(modules).flatMap(([refName, keys]) =>
|
|
441
|
+
(keys[family] ?? [])
|
|
442
|
+
.filter((key) => {
|
|
443
|
+
const entry = table.lookup(family, key);
|
|
444
|
+
return baseModules.includes(refName)
|
|
445
|
+
? !entry?.base
|
|
446
|
+
: !entry?.owners.some(({ module }) => module === refName);
|
|
447
|
+
})
|
|
448
|
+
.map((key) => `${family}.${key} is answered by ${refName}'s own runtime, which does not own it`),
|
|
449
|
+
),
|
|
450
|
+
]);
|
|
451
|
+
expect(misses).toEqual([]);
|
|
452
|
+
const owners = runtimeFamilies.flatMap((family) =>
|
|
453
|
+
table.keysOf(family).flatMap((key) => table.lookup(family, key)?.owners ?? []),
|
|
454
|
+
);
|
|
455
|
+
expect([...new Set(owners.map(({ scope, module }) => `${scope}/${module}`))].sort()).toEqual([
|
|
456
|
+
"apps/demo/demo",
|
|
457
|
+
"apps/demo/item",
|
|
458
|
+
"libs/kit/tag",
|
|
459
|
+
]);
|
|
460
|
+
}, 120_000);
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
const serviceFiles = (name: string, endpointName: string): Record<string, string> => {
|
|
464
|
+
const Name = name.charAt(0).toUpperCase() + name.slice(1);
|
|
465
|
+
return {
|
|
466
|
+
[`lib/_${name}/${name}.dictionary.ts`]: `import { serviceDictionary } from "akanjs/dictionary";
|
|
467
|
+
|
|
468
|
+
import type { ${Name}Endpoint } from "./${name}.signal";
|
|
469
|
+
|
|
470
|
+
export const dictionary = serviceDictionary(["en", "ko"])
|
|
471
|
+
.endpoint<${Name}Endpoint>((fn) => ({
|
|
472
|
+
${endpointName}: fn(["${Name}", "${Name}"]),
|
|
473
|
+
}))
|
|
474
|
+
.translate({});
|
|
475
|
+
`,
|
|
476
|
+
[`lib/_${name}/${name}.service.ts`]: `import { serve } from "akanjs/service";
|
|
477
|
+
|
|
478
|
+
export class ${Name}Service extends serve("${name}" as const, () => ({})) {}
|
|
479
|
+
`,
|
|
480
|
+
[`lib/_${name}/${name}.signal.ts`]: `import { endpoint, internal, Public } from "akanjs/signal";
|
|
481
|
+
|
|
482
|
+
import * as srv from "../srv";
|
|
483
|
+
|
|
484
|
+
export class ${Name}Internal extends internal(srv.${name}, () => ({})) {}
|
|
485
|
+
|
|
486
|
+
export class ${Name}Endpoint extends endpoint(srv.${name}, ({ query }) => ({
|
|
487
|
+
${endpointName}: query(String, { guards: [Public], mcp: false }).exec(() => ""),
|
|
488
|
+
})) {}
|
|
489
|
+
`,
|
|
490
|
+
};
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
//? `audit` follows `item` in the lib's signal, so an app that extends `item` shows whether its pieces keep that order.
|
|
494
|
+
const stockFiles = { ...kitFiles, ...serviceFiles("audit", "auditTrail") };
|
|
495
|
+
const shopFilesOf = (lib: string) => ({
|
|
496
|
+
...Object.fromEntries(
|
|
497
|
+
Object.entries(demoFiles).map(([file, content]) => [file, content.replaceAll("@libs/kit/", `@libs/${lib}/`)]),
|
|
498
|
+
),
|
|
499
|
+
...serviceFiles("ping", "pingAt"),
|
|
500
|
+
"lib/_note/note.dictionary.ts": `import { serviceDictionary } from "akanjs/dictionary";
|
|
501
|
+
|
|
502
|
+
export const dictionary = serviceDictionary(["en", "ko"]).translate({});
|
|
503
|
+
`,
|
|
504
|
+
"lib/_note/note.store.ts": `import { store } from "akanjs/store";
|
|
505
|
+
|
|
506
|
+
export class NoteStore extends store("note" as const, () => ({ noteText: "" })) {}
|
|
507
|
+
`,
|
|
508
|
+
});
|
|
509
|
+
const writeShopWorkspace = (app: string, lib: string) =>
|
|
510
|
+
writeWorkspace({ app, lib, libFiles: stockFiles, appFiles: shopFilesOf(lib) });
|
|
511
|
+
|
|
512
|
+
//? Rewrites files instead of redirecting with a runtime `Bun.plugin`, under which Bun 1.4 leaves macro calls un-inlined.
|
|
513
|
+
const pointScopes = async (root: string, scopes: string[], targets: Record<string, string>) => {
|
|
514
|
+
for (const scope of scopes)
|
|
515
|
+
for (const [file, target] of Object.entries(targets))
|
|
516
|
+
await writeText(path.join(root, scope, "lib", file), `export * from "${target}";\n`);
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
const runtimeKeysScript = (app: string, { browser = false } = {}) => `
|
|
520
|
+
${browser ? `Object.assign(globalThis, { window: globalThis, location: new URL("http://localhost:4200/") });\n` : ""}const { FetchClient } = await import("akanjs/fetch");
|
|
521
|
+
const { fetch, sig } = await import("./apps/${app}/lib/useClient.ts");
|
|
522
|
+
const { st } = await import("./apps/${app}/lib/st.ts");
|
|
523
|
+
const serializedSignal = fetch.serializedSignal;
|
|
524
|
+
console.log(JSON.stringify({
|
|
525
|
+
"st.get": Object.keys(st.get()),
|
|
526
|
+
"st.do": Object.keys(st.do),
|
|
527
|
+
"st.use": Object.keys(st.use),
|
|
528
|
+
"st.slice": Object.keys(st.slice),
|
|
529
|
+
"fetch.slice": Object.keys(fetch.slice),
|
|
530
|
+
sig: Object.keys(sig),
|
|
531
|
+
"fetch.serializedSignal": Object.keys(serializedSignal),
|
|
532
|
+
"FetchClient.claimsOf": Object.entries(serializedSignal).flatMap(([refName, signal]) =>
|
|
533
|
+
FetchClient.claimsOf(refName, signal).handlers.map(({ key }) => key),
|
|
534
|
+
),
|
|
535
|
+
}));
|
|
536
|
+
`;
|
|
537
|
+
|
|
538
|
+
const lonePieceScript = (app: string, lib: string, piece: string) => `
|
|
539
|
+
const { StoreRegistry, st } = await import("akanjs/store");
|
|
540
|
+
const storesBefore = new Set(StoreRegistry.stores.keys());
|
|
541
|
+
await import("./apps/${app}/lib/__client/${piece}.st.ts");
|
|
542
|
+
const appPage = await import("./apps/${app}/lib/usePage.ts");
|
|
543
|
+
const libPage = await import("./libs/${lib}/lib/usePage.ts");
|
|
544
|
+
const moduleActions = ["pickLabel", "loadItemNote", "refreshItemCount"];
|
|
545
|
+
const moduleState = ["label", "noteDraft", "itemCount", "noteText"];
|
|
546
|
+
console.log(JSON.stringify({
|
|
547
|
+
stores: [...StoreRegistry.stores.keys()].filter((key) => !storesBefore.has(key)),
|
|
548
|
+
actions: moduleActions.filter((key) => key in st.do),
|
|
549
|
+
state: moduleState.filter((key) => key in st.get()),
|
|
550
|
+
appSignal: Object.keys(appPage.fetch.ownSerializedSignal),
|
|
551
|
+
libSignal: Object.keys(libPage.fetch.ownSerializedSignal),
|
|
552
|
+
}));
|
|
553
|
+
`;
|
|
554
|
+
|
|
555
|
+
const basePieceScript = (app: string) => `
|
|
556
|
+
const { ConstantRegistry } = await import("akanjs/constant");
|
|
557
|
+
const { fetch } = await import("./apps/${app}/lib/usePage.ts");
|
|
558
|
+
await import("./apps/${app}/lib/__client/_base.fetch.ts");
|
|
559
|
+
console.log(JSON.stringify({
|
|
560
|
+
signal: Object.keys(fetch.ownSerializedSignal),
|
|
561
|
+
ping: typeof fetch.ping,
|
|
562
|
+
constants: ["item"].filter((name) => ConstantRegistry.getDatabase(name, { allowEmpty: true })),
|
|
563
|
+
}));
|
|
564
|
+
`;
|
|
565
|
+
|
|
566
|
+
const keptByWholeScript = (app: string) => `
|
|
567
|
+
const { st } = await import("akanjs/store");
|
|
568
|
+
await import("./apps/${app}/lib/__client/demo.st.ts");
|
|
569
|
+
const pickLabel = st.do.pickLabel;
|
|
570
|
+
await pickLabel("picked");
|
|
571
|
+
await import("./apps/${app}/lib/st.ts");
|
|
572
|
+
console.log(JSON.stringify({ samePickLabel: st.do.pickLabel === pickLabel, label: st.get().label }));
|
|
573
|
+
`;
|
|
574
|
+
|
|
575
|
+
const appStoreAloneScript = (app: string) => `
|
|
576
|
+
const { StoreRegistry } = await import("akanjs/store");
|
|
577
|
+
const { ItemStore } = await import("./apps/${app}/lib/item/item.store.ts");
|
|
578
|
+
StoreRegistry.register(ItemStore);
|
|
579
|
+
const actions = ItemStore[Symbol.for("akan.action")];
|
|
580
|
+
console.log(JSON.stringify({ actions: ["refreshItemCount", "loadItemNote"].filter((key) => key in actions) }));
|
|
581
|
+
`;
|
|
582
|
+
|
|
583
|
+
const orderPath = path.join(import.meta.dir, "clientRuntimeKeyOrder.fixture.json");
|
|
584
|
+
const howToRecordOrder =
|
|
585
|
+
"The order of the keys an app's whole client runtime answers no longer matches clientRuntimeKeyOrder.fixture.json. " +
|
|
586
|
+
"If the change is intended, record it with AKAN_RECORD_CLIENT_RUNTIME_KEYS=1 and review the fixture's diff.";
|
|
587
|
+
|
|
588
|
+
//? A workspace per test: the temp root goes after each test, and the scan caches an app or lib by name.
|
|
589
|
+
const uploadFilesOf = () => {
|
|
590
|
+
const file = kitModuleNamed("file", "File");
|
|
591
|
+
const user = kitModuleNamed("user", "User");
|
|
592
|
+
return {
|
|
593
|
+
...stockFiles,
|
|
594
|
+
...file,
|
|
595
|
+
...user,
|
|
596
|
+
"lib/file/file.signal.ts": (file["lib/file/file.signal.ts"] ?? "")
|
|
597
|
+
.replace('import { Int } from "akanjs/base";', 'import { Int, Upload } from "akanjs/base";')
|
|
598
|
+
.replace('import * as srv from "../srv";', 'import * as cnst from "../cnst";\nimport * as srv from "../srv";')
|
|
599
|
+
.replace("({ query }) => ({", "({ query, mutation }) => ({")
|
|
600
|
+
.replace(
|
|
601
|
+
" fileCount:",
|
|
602
|
+
` addFiles: mutation([cnst.File], { guards: [Public], fileUpload: true, mcp: false })
|
|
603
|
+
.body("files", [Upload])
|
|
604
|
+
.exec(() => []),
|
|
605
|
+
fileCount:`,
|
|
606
|
+
),
|
|
607
|
+
"lib/user/user.constant.ts": (user["lib/user/user.constant.ts"] ?? "")
|
|
608
|
+
.replace(
|
|
609
|
+
'import { via } from "akanjs/constant";',
|
|
610
|
+
'import { via } from "akanjs/constant";\n\nimport { File } from "../file/file.constant";',
|
|
611
|
+
)
|
|
612
|
+
.replace(" name: field(String),", " name: field(String),\n image: field(File, { nullable: true }),"),
|
|
613
|
+
};
|
|
614
|
+
};
|
|
615
|
+
|
|
616
|
+
const uploadSetterScript = (lib: string) => `
|
|
617
|
+
const { st } = await import("akanjs/store");
|
|
618
|
+
await import("./libs/${lib}/lib/__client/user.st.ts");
|
|
619
|
+
const page = await import("./libs/${lib}/lib/usePage.ts");
|
|
620
|
+
console.log(JSON.stringify({
|
|
621
|
+
upload: typeof st.do.uploadImageOnUser,
|
|
622
|
+
signal: Object.keys(page.fetch.ownSerializedSignal).sort(),
|
|
623
|
+
}));
|
|
624
|
+
`;
|
|
625
|
+
|
|
626
|
+
const routeRuntimeScript = (app: string, pieces: string[]) => `
|
|
627
|
+
const { StoreRegistry } = await import("akanjs/store");
|
|
628
|
+
const storesBefore = new Set(StoreRegistry.stores.keys());
|
|
629
|
+
${pieces.map((piece) => `await import("./${piece}.ts");`).join("\n")}
|
|
630
|
+
const page = await import("./apps/${app}/lib/usePage.ts");
|
|
631
|
+
console.log(JSON.stringify({
|
|
632
|
+
stores: [...StoreRegistry.stores.keys()].filter((key) => !storesBefore.has(key)).sort(),
|
|
633
|
+
signal: Object.keys(page.fetch.ownSerializedSignal).sort(),
|
|
634
|
+
}));
|
|
635
|
+
`;
|
|
636
|
+
|
|
637
|
+
const devkitFile = (file: string) => JSON.stringify(path.resolve(import.meta.dir, "..", file));
|
|
638
|
+
|
|
639
|
+
interface BundleOptions {
|
|
640
|
+
descriptors?: boolean;
|
|
641
|
+
editBetween?: { file: string; from: string; to: string };
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
interface Bundled {
|
|
645
|
+
outputs: string[];
|
|
646
|
+
pages: string[];
|
|
647
|
+
answered: number;
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
const bundleScript = (
|
|
651
|
+
root: string,
|
|
652
|
+
appName: string,
|
|
653
|
+
entries: string[],
|
|
654
|
+
{ descriptors = false, editBetween }: BundleOptions,
|
|
655
|
+
) => `
|
|
656
|
+
const path = await import("node:path");
|
|
657
|
+
const { AppExecutor } = await import(${devkitFile("executors/appExecutor.ts")});
|
|
658
|
+
const { WorkspaceExecutor } = await import(${devkitFile("executors/workspaceExecutor.ts")});
|
|
659
|
+
const { createBarrelImportsPlugin } = await import(${devkitFile("transforms/barrelImportsPlugin.ts")});
|
|
660
|
+
const { RouteRuntime } = await import(${devkitFile("transforms/routeRuntime.ts")});
|
|
661
|
+
const { SignalDescriptors } = await import(${devkitFile("transforms/signalDescriptors.ts")});
|
|
662
|
+
const [root, appName, entries, withDescriptors, edit] = ${JSON.stringify([root, appName, entries, descriptors, editBetween ?? null])};
|
|
663
|
+
const app = AppExecutor.from(new WorkspaceExecutor({ workspaceRoot: root, repoName: "repo" }), appName);
|
|
664
|
+
const routeRuntime = await RouteRuntime.read(root, "apps/" + appName);
|
|
665
|
+
if (!routeRuntime) throw new Error("the fixture app has no assembled runtime pieces");
|
|
666
|
+
const build = async (outdir) => {
|
|
667
|
+
let answered = 0;
|
|
668
|
+
const signalDescriptors = new SignalDescriptors(root, routeRuntime.table.layers.map(({ scope }) => scope));
|
|
669
|
+
const inline = signalDescriptors.inline.bind(signalDescriptors);
|
|
670
|
+
signalDescriptors.inline = async (...args) => {
|
|
671
|
+
const contents = await inline(...args);
|
|
672
|
+
if (contents !== null) answered += 1;
|
|
673
|
+
return contents;
|
|
674
|
+
};
|
|
675
|
+
const built = await Bun.build({
|
|
676
|
+
entrypoints: entries.map((entry) => path.join(root, entry)),
|
|
677
|
+
target: "browser",
|
|
678
|
+
splitting: true,
|
|
679
|
+
root,
|
|
680
|
+
outdir: path.join(root, "bundled", outdir),
|
|
681
|
+
define: { "process.env.AKAN_PUBLIC_APP_NAME": JSON.stringify(appName) },
|
|
682
|
+
plugins: [
|
|
683
|
+
...(withDescriptors ? [signalDescriptors.plugin] : []),
|
|
684
|
+
await createBarrelImportsPlugin(app, { routeRuntime, modelRuntime: routeRuntime.wholeSource }),
|
|
685
|
+
],
|
|
686
|
+
});
|
|
687
|
+
return {
|
|
688
|
+
outputs: built.outputs.map((output) => output.path),
|
|
689
|
+
pages: built.outputs.filter(({ kind }) => kind === "entry-point").map((output) => path.relative(root, output.path)),
|
|
690
|
+
answered,
|
|
691
|
+
};
|
|
692
|
+
};
|
|
693
|
+
const outdir = entries.join("+").replaceAll(/[^\\w+]/g, "-") + (withDescriptors ? "-descriptors" : "");
|
|
694
|
+
const built = await build(outdir);
|
|
695
|
+
if (edit) {
|
|
696
|
+
const file = path.join(root, edit.file);
|
|
697
|
+
await Bun.write(file, (await Bun.file(file).text()).replace(edit.from, edit.to));
|
|
698
|
+
}
|
|
699
|
+
console.log(JSON.stringify(edit ? { ...built, rebuilt: await build(outdir + "-rebuilt") } : built));
|
|
700
|
+
`;
|
|
701
|
+
|
|
702
|
+
//? One entry is one page's bundle: with several, a shared chunk can run a store before the file a page reaches first.
|
|
703
|
+
//? Built in its own process: in this one a macro can resolve `@libs/*` by a tsconfig cached before the fixture wrote its paths.
|
|
704
|
+
const bundleForBrowser = async (root: string, appName: string, entries: string[], options: BundleOptions = {}) =>
|
|
705
|
+
(await evaluate(root, bundleScript(root, appName, entries, options), appName)) as unknown as Bundled & {
|
|
706
|
+
rebuilt?: Bundled;
|
|
707
|
+
};
|
|
708
|
+
|
|
709
|
+
describe("an app's client runtime pieces", () => {
|
|
710
|
+
test("leave the whole client runtime answering its keys in the order it did before the pieces, in a browser and outside one", async () => {
|
|
711
|
+
const { root } = await writeShopWorkspace("bazaar", "crate");
|
|
712
|
+
const order = {
|
|
713
|
+
node: await evaluate(root, runtimeKeysScript("bazaar"), "bazaar"),
|
|
714
|
+
browser: await evaluate(root, runtimeKeysScript("bazaar", { browser: true }), "bazaar"),
|
|
715
|
+
};
|
|
716
|
+
if (process.env.AKAN_RECORD_CLIENT_RUNTIME_KEYS === "1")
|
|
717
|
+
await Bun.write(orderPath, `${JSON.stringify(order, null, 2)}\n`);
|
|
718
|
+
expect(order, howToRecordOrder).toEqual(await Bun.file(orderPath).json());
|
|
719
|
+
}, 120_000);
|
|
720
|
+
|
|
721
|
+
test("give each module a fetch piece for its signal and a store piece for its store, and leave with the module", async () => {
|
|
722
|
+
const { root, app } = await writeShopWorkspace("shop", "stock");
|
|
723
|
+
const appPieces = path.join(root, "apps/shop/lib/__client");
|
|
724
|
+
const read = (file: string) => Bun.file(path.join(appPieces, file)).text();
|
|
725
|
+
const scopePieces = ["_base.fetch.ts", "_st.ts", "_useClient.ts", "audit.fetch.ts"];
|
|
726
|
+
const modulePieces = ["demo.fetch.ts", "demo.st.ts", "item.cnst.ts", "item.fetch.ts", "item.st.ts", "note.st.ts"];
|
|
727
|
+
const references = ["item.ref.ts", "refs.ts"];
|
|
728
|
+
expect((await readdir(appPieces)).sort()).toEqual(
|
|
729
|
+
[...scopePieces, ...modulePieces, "ping.fetch.ts", ...references].sort(),
|
|
730
|
+
);
|
|
731
|
+
expect((await readdir(path.join(root, "libs/stock/lib/__client"))).sort()).toEqual([
|
|
732
|
+
...scopePieces,
|
|
733
|
+
"item.cnst.ts",
|
|
734
|
+
"item.fetch.ts",
|
|
735
|
+
"item.st.ts",
|
|
736
|
+
]);
|
|
737
|
+
expect(await read("item.cnst.ts")).toContain(
|
|
738
|
+
'import { item as lib0 } from "@libs/stock/lib/__client/item.cnst";\nimport * as cnst from "../item/item.constant";\n\nloadedAfter(lib0);\nexport const item = ConstantRegistry.buildModel("item" as const, cnst.ItemInput,',
|
|
739
|
+
);
|
|
740
|
+
expect(await read("item.cnst.ts")).toEndWith(', "shop");\nexport { item as loaded };\n');
|
|
741
|
+
expect(await read("_base.fetch.ts")).not.toContain("@libs/");
|
|
742
|
+
expect(await read("_base.fetch.ts")).toContain('getSerializedSignalOf("base")');
|
|
743
|
+
expect(await read("audit.fetch.ts")).toContain(
|
|
744
|
+
'import { loaded as lib0 } from "@libs/stock/lib/__client/audit.fetch";',
|
|
745
|
+
);
|
|
746
|
+
expect(await read("item.fetch.ts")).toContain(
|
|
747
|
+
'import { loaded as lib0 } from "@libs/stock/lib/__client/item.fetch";\nimport { loaded as cnst0 } from "./item.cnst";',
|
|
748
|
+
);
|
|
749
|
+
expect(await read("item.fetch.ts")).toContain(
|
|
750
|
+
"\nexport const loaded = FetchClient.build<typeof signal>([lib0, cnst0], ",
|
|
751
|
+
);
|
|
752
|
+
expect(await read("item.fetch.ts")).not.toContain("loadedAfter");
|
|
753
|
+
expect(await read("ping.fetch.ts")).not.toContain("@libs/");
|
|
754
|
+
expect(await read("ping.fetch.ts")).toContain('getSerializedSignalOf("ping")');
|
|
755
|
+
expect(await read("demo.st.ts")).toContain('import { loaded as fetch0 } from "./demo.fetch";');
|
|
756
|
+
expect(await read("demo.st.ts")).toContain('import { DemoStore } from "../_demo/demo.store";');
|
|
757
|
+
expect(await read("item.st.ts")).toContain(
|
|
758
|
+
'import { loaded as cnst0 } from "./item.cnst";\nimport { loaded as fetch0 } from "./item.fetch";\nimport { item as lib0 } from "@libs/stock/lib/__client/item.st";\nimport { ItemStore } from "../item/item.store";\n\nloadedAfter(cnst0, fetch0, lib0);\nexport const item = StoreRegistry.register(ItemStore);',
|
|
759
|
+
);
|
|
760
|
+
expect(await read("note.st.ts")).not.toContain(".fetch");
|
|
761
|
+
expect(await read("note.st.ts")).not.toContain("loadedAfter");
|
|
762
|
+
expect(await read("item.ref.ts")).toBe('\n"use client";\n\nexport const reference = "item";\n');
|
|
763
|
+
expect(await read("refs.ts")).toBe(
|
|
764
|
+
'\nimport { FetchClient } from "akanjs/fetch";\nimport { reference as ref0 } from "./item.ref";\n\nif (process.env.AKAN_PUBLIC_RENDER_ENV !== "csr") FetchClient.setModelRuntimes({ "item": ref0 });\n',
|
|
765
|
+
);
|
|
766
|
+
expect((await read("_useClient.ts")).match(/(?<=from "\.\/)[^"]+(?=";)/g)).toEqual([
|
|
767
|
+
"_base.fetch",
|
|
768
|
+
"item.fetch",
|
|
769
|
+
"audit.fetch",
|
|
770
|
+
"demo.fetch",
|
|
771
|
+
"ping.fetch",
|
|
772
|
+
]);
|
|
773
|
+
expect(await read("_useClient.ts")).toContain("\nloadedAfter(base, module0, module1, module2, module3);\n");
|
|
774
|
+
expect(await read("_st.ts")).toContain('import { RootStore as stock } from "@libs/stock/lib/__client/_st";');
|
|
775
|
+
expect(await read("_st.ts")).toContain('import { sig } from "./_useClient";');
|
|
776
|
+
expect(await read("_st.ts")).toContain("\nloadedAfter(sig);\n");
|
|
777
|
+
for (const whole of ["useClient.ts", "st.ts", "usePage.ts"])
|
|
778
|
+
expect(await Bun.file(path.join(root, "apps/shop/lib", whole)).text()).not.toContain("__client");
|
|
779
|
+
|
|
780
|
+
await rm(path.join(root, "apps/shop/lib/_ping"), { recursive: true });
|
|
781
|
+
await writeText(path.join(appPieces, "stale.st.ts"), "export {};\n");
|
|
782
|
+
await app.scan({ refresh: true });
|
|
783
|
+
expect((await readdir(appPieces)).sort()).toEqual([...scopePieces, ...modulePieces, ...references].sort());
|
|
784
|
+
expect(await read("_useClient.ts")).not.toContain("ping");
|
|
785
|
+
}, 120_000);
|
|
786
|
+
|
|
787
|
+
test("load one module's store piece with only that module's store and descriptors, lib modules included", async () => {
|
|
788
|
+
const { root } = await writeShopWorkspace("mall", "depot");
|
|
789
|
+
expect(await evaluate(root, lonePieceScript("mall", "depot", "demo"), "mall")).toEqual({
|
|
790
|
+
stores: ["demo"],
|
|
791
|
+
actions: ["pickLabel"],
|
|
792
|
+
state: ["label"],
|
|
793
|
+
appSignal: ["demo"],
|
|
794
|
+
libSignal: [],
|
|
795
|
+
});
|
|
796
|
+
expect(await evaluate(root, keptByWholeScript("mall"), "mall")).toEqual({ samePickLabel: true, label: "picked" });
|
|
797
|
+
await pointScopes(root, ["apps/mall", "libs/depot"], { "useClient.ts": "./usePage" });
|
|
798
|
+
expect(await evaluate(root, lonePieceScript("mall", "depot", "item"), "mall")).toEqual({
|
|
799
|
+
stores: ["item"],
|
|
800
|
+
actions: ["loadItemNote", "refreshItemCount"],
|
|
801
|
+
state: ["noteDraft", "itemCount"],
|
|
802
|
+
appSignal: ["item"],
|
|
803
|
+
libSignal: ["item"],
|
|
804
|
+
});
|
|
805
|
+
}, 120_000);
|
|
806
|
+
|
|
807
|
+
test("load the framework's own descriptors beside the page runtime without the app's constants", async () => {
|
|
808
|
+
const { root } = await writeShopWorkspace("kiosk", "shelf");
|
|
809
|
+
expect(await evaluate(root, basePieceScript("kiosk"), "kiosk")).toEqual({
|
|
810
|
+
signal: ["base", "agent"],
|
|
811
|
+
ping: "function",
|
|
812
|
+
constants: [],
|
|
813
|
+
});
|
|
814
|
+
}, 120_000);
|
|
815
|
+
|
|
816
|
+
test("let an app store file imported on its own keep the actions of the lib store it extends", async () => {
|
|
817
|
+
const { root } = await writeShopWorkspace("plaza", "cargo");
|
|
818
|
+
expect(await evaluate(root, appStoreAloneScript("plaza"), "plaza")).toEqual({
|
|
819
|
+
actions: ["refreshItemCount", "loadItemNote"],
|
|
820
|
+
});
|
|
821
|
+
}, 120_000);
|
|
822
|
+
|
|
823
|
+
test("load the upload module's descriptors before a store whose model holds a file, so its piece alone has the upload action", async () => {
|
|
824
|
+
const { root } = await writeWorkspace({
|
|
825
|
+
app: "studio",
|
|
826
|
+
lib: "locker",
|
|
827
|
+
libFiles: uploadFilesOf(),
|
|
828
|
+
appFiles: shopFilesOf("locker"),
|
|
829
|
+
});
|
|
830
|
+
const piece = await Bun.file(path.join(root, "libs/locker/lib/__client/user.st.ts")).text();
|
|
831
|
+
expect(piece).toContain(
|
|
832
|
+
'import { loaded as fetch0 } from "./file.fetch";\nimport { loaded as fetch1 } from "./user.fetch";\n',
|
|
833
|
+
);
|
|
834
|
+
expect(piece).toContain(
|
|
835
|
+
'import { loaded as cnst0 } from "./user.cnst";\nimport { loaded as fetch0 } from "./file.fetch";\n',
|
|
836
|
+
);
|
|
837
|
+
expect(piece).toContain(
|
|
838
|
+
"\nloadedAfter(cnst0, fetch0, fetch1);\nexport const user = StoreRegistry.register(UserStore);",
|
|
839
|
+
);
|
|
840
|
+
expect(await Bun.file(path.join(root, "libs/locker/lib/__client/item.st.ts")).text()).not.toContain("file.fetch");
|
|
841
|
+
await pointScopes(root, ["apps/studio", "libs/locker"], { "useClient.ts": "./usePage" });
|
|
842
|
+
expect(await evaluate(root, uploadSetterScript("locker"), "studio")).toEqual({
|
|
843
|
+
upload: "function",
|
|
844
|
+
signal: ["file", "user"],
|
|
845
|
+
});
|
|
846
|
+
}, 120_000);
|
|
847
|
+
|
|
848
|
+
test("say which sync to run again when a scope's modules cannot be read, since its store files then load no upload descriptors first", async () => {
|
|
849
|
+
const saidWhenSynced = async (app: string, lib: string) => {
|
|
850
|
+
const warnings: string[] = [];
|
|
851
|
+
const warn = spyOn(Logger.prototype, "warn").mockImplementation((message: string) => {
|
|
852
|
+
warnings.push(message);
|
|
853
|
+
});
|
|
854
|
+
const readScopes = spyOn(RuntimeNameTable, "readScopes").mockRejectedValue(
|
|
855
|
+
new Error("user.constant.ts is unreadable"),
|
|
856
|
+
);
|
|
857
|
+
try {
|
|
858
|
+
const { root } = await writeWorkspace({
|
|
859
|
+
app,
|
|
860
|
+
lib,
|
|
861
|
+
libFiles: uploadFilesOf(),
|
|
862
|
+
appFiles: shopFilesOf(lib),
|
|
863
|
+
});
|
|
864
|
+
const piece = await Bun.file(path.join(root, `libs/${lib}/lib/__client/user.st.ts`)).text();
|
|
865
|
+
expect(piece).not.toContain("file.fetch");
|
|
866
|
+
} finally {
|
|
867
|
+
readScopes.mockRestore();
|
|
868
|
+
warn.mockRestore();
|
|
869
|
+
}
|
|
870
|
+
return warnings.filter((message) => message.includes("[client-runtime]"));
|
|
871
|
+
};
|
|
872
|
+
|
|
873
|
+
const said = await saidWhenSynced("depot", "hangar");
|
|
874
|
+
expect(said.find((message) => message.includes("libs/hangar/lib/__client"))).toContain(
|
|
875
|
+
"(user.constant.ts is unreadable)",
|
|
876
|
+
);
|
|
877
|
+
expect(said.find((message) => message.includes("libs/hangar/lib/__client"))).toContain("Run `akan sync hangar`");
|
|
878
|
+
expect(said.some((message) => message.includes("Run `akan sync depot`"))).toBe(true);
|
|
879
|
+
}, 120_000);
|
|
880
|
+
|
|
881
|
+
test("give a client file exactly the pieces of the modules it names, each generated and each loading only its module", async () => {
|
|
882
|
+
const { root } = await writeShopWorkspace("outlet", "pallet");
|
|
883
|
+
const runtime = await RouteRuntime.read(root, "apps/outlet");
|
|
884
|
+
if (!runtime) throw new Error("the fixture app has no assembled runtime pieces");
|
|
885
|
+
const file = "apps/outlet/ui/Card.tsx";
|
|
886
|
+
const text =
|
|
887
|
+
'import { fetch, st } from "@apps/outlet/client";\nexport const Card = () => [st.use.label(), fetch.pingAt()];\n';
|
|
888
|
+
const verdict = RuntimeUse.analyze({ fileName: file, text }, runtime.table);
|
|
889
|
+
const result = runtime.transform(text, path.join(root, file));
|
|
890
|
+
|
|
891
|
+
expect(
|
|
892
|
+
verdict.resolvable ? new Set(verdict.owners.map(({ module, needs }) => `${module} ${needs}`)) : null,
|
|
893
|
+
).toEqual(new Set(["demo store", "ping descriptor"]));
|
|
894
|
+
expect(result?.pieces).toEqual([
|
|
895
|
+
"apps/outlet/lib/__client/demo.fetch",
|
|
896
|
+
"apps/outlet/lib/__client/ping.fetch",
|
|
897
|
+
"apps/outlet/lib/__client/demo.st",
|
|
898
|
+
]);
|
|
899
|
+
await pointScopes(root, ["apps/outlet", "libs/pallet"], { "useClient.ts": "./usePage" });
|
|
900
|
+
expect(await evaluate(root, routeRuntimeScript("outlet", result?.pieces ?? []), "outlet")).toEqual({
|
|
901
|
+
stores: ["demo"],
|
|
902
|
+
signal: ["demo", "ping"],
|
|
903
|
+
});
|
|
904
|
+
}, 120_000);
|
|
905
|
+
|
|
906
|
+
test("bundle for a browser with each named module's descriptors once for each scope declaring its signal, no other module's and nothing its signal or service runs on the server, by the macro or by descriptors read once", async () => {
|
|
907
|
+
const files: Record<string, string> = shopFilesOf("trolley");
|
|
908
|
+
const pingSignal = "lib/_ping/ping.signal.ts";
|
|
909
|
+
const pingService = "lib/_ping/ping.service.ts";
|
|
910
|
+
const temp = await writeWorkspace({
|
|
911
|
+
app: "stall",
|
|
912
|
+
lib: "trolley",
|
|
913
|
+
libFiles: stockFiles,
|
|
914
|
+
appFiles: {
|
|
915
|
+
...files,
|
|
916
|
+
[pingSignal]: `${files[pingSignal]}`.replace('.exec(() => "")', '.exec(() => "ran-on-the-server")'),
|
|
917
|
+
[pingService]: `${files[pingService]}`.replace(
|
|
918
|
+
")) {}",
|
|
919
|
+
')) {\n pingNow() {\n return "served-on-the-server";\n }\n}',
|
|
920
|
+
),
|
|
921
|
+
"ui/Card.tsx":
|
|
922
|
+
'import { fetch, st } from "@apps/stall/client";\nexport const Card = () => [st.use.label(), fetch.pingAt()];\n',
|
|
923
|
+
"ui/Tile.tsx": 'import { fetch } from "@apps/stall/client";\nexport const Tile = () => fetch.pingAt();\n',
|
|
924
|
+
"ui/Count.tsx": 'import { st } from "@apps/stall/client";\nexport const Count = () => st.use.itemCount();\n',
|
|
925
|
+
},
|
|
926
|
+
});
|
|
927
|
+
for (const descriptors of [false, true]) {
|
|
928
|
+
const { outputs, answered } = await bundleForBrowser(
|
|
929
|
+
temp.root,
|
|
930
|
+
"stall",
|
|
931
|
+
["Card", "Tile", "Count"].map((name) => `apps/stall/ui/${name}.tsx`),
|
|
932
|
+
{ descriptors },
|
|
933
|
+
);
|
|
934
|
+
const bundled = (await Promise.all(outputs.map((output) => Bun.file(output).text()))).join("\n");
|
|
935
|
+
const descriptorsOf = (endpoint: string) =>
|
|
936
|
+
bundled.match(new RegExp(`\\b${endpoint}: \\{\\s+type: "`, "g"))?.length ?? 0;
|
|
937
|
+
|
|
938
|
+
expect(outputs.length).toBeGreaterThan(3);
|
|
939
|
+
expect(answered > 0).toBe(descriptors);
|
|
940
|
+
expect(["pingAt", "itemCount", "auditTrail"].map(descriptorsOf)).toEqual([1, 2, 0]);
|
|
941
|
+
expect(bundled).not.toContain("ran-on-the-server");
|
|
942
|
+
expect(bundled).not.toContain("served-on-the-server");
|
|
943
|
+
}
|
|
944
|
+
}, 120_000);
|
|
945
|
+
|
|
946
|
+
test("answer each build's pieces from its signals as they are then, so an edit between two builds in one process ships the new descriptors", async () => {
|
|
947
|
+
const temp = await writeWorkspace({
|
|
948
|
+
app: "booth",
|
|
949
|
+
lib: "hamper",
|
|
950
|
+
libFiles: stockFiles,
|
|
951
|
+
appFiles: {
|
|
952
|
+
...shopFilesOf("hamper"),
|
|
953
|
+
"ui/Tile.tsx": 'import { fetch } from "@apps/booth/client";\nexport const Tile = () => fetch.pingAt();\n',
|
|
954
|
+
},
|
|
955
|
+
});
|
|
956
|
+
const { outputs, answered, rebuilt } = await bundleForBrowser(temp.root, "booth", ["apps/booth/ui/Tile.tsx"], {
|
|
957
|
+
descriptors: true,
|
|
958
|
+
editBetween: {
|
|
959
|
+
file: "apps/booth/lib/_ping/ping.signal.ts",
|
|
960
|
+
from: "query(String, { guards",
|
|
961
|
+
to: "query(String, { nullable: true, guards",
|
|
962
|
+
},
|
|
963
|
+
});
|
|
964
|
+
const returnsOf = async (files: string[]) => {
|
|
965
|
+
const bundled = (await Promise.all(files.map((file) => Bun.file(file).text()))).join("\n");
|
|
966
|
+
return bundled
|
|
967
|
+
.match(/\bpingAt: \{[^}]*?returns: \{([^}]*)\}/)?.[1]
|
|
968
|
+
?.replaceAll(/\s+/g, " ")
|
|
969
|
+
.trim();
|
|
970
|
+
};
|
|
971
|
+
|
|
972
|
+
expect([answered > 0, (rebuilt?.answered ?? 0) > 0]).toEqual([true, true]);
|
|
973
|
+
expect([await returnsOf(outputs), await returnsOf(rebuilt?.outputs ?? [])]).toEqual([
|
|
974
|
+
'refName: "String"',
|
|
975
|
+
'refName: "String", nullable: true',
|
|
976
|
+
]);
|
|
977
|
+
}, 120_000);
|
|
978
|
+
|
|
979
|
+
test("assemble the same store, fetch and signal keys as the whole client runtime, in a browser and outside one", async () => {
|
|
980
|
+
const { root } = await writeShopWorkspace("arcade", "vault");
|
|
981
|
+
const evaluateBoth = async () => ({
|
|
982
|
+
node: await evaluate(root, runtimeKeysScript("arcade"), "arcade"),
|
|
983
|
+
browser: await evaluate(root, runtimeKeysScript("arcade", { browser: true }), "arcade"),
|
|
984
|
+
});
|
|
985
|
+
const sorted = (keys: Record<string, Record<string, unknown>>) =>
|
|
986
|
+
Object.fromEntries(
|
|
987
|
+
Object.entries(keys).map(([env, byKey]) => [
|
|
988
|
+
env,
|
|
989
|
+
Object.fromEntries(Object.entries(byKey).map(([key, value]) => [key, [...(value as string[])].sort()])),
|
|
990
|
+
]),
|
|
991
|
+
);
|
|
992
|
+
const whole = await evaluateBoth();
|
|
993
|
+
await pointScopes(root, ["apps/arcade", "libs/vault"], {
|
|
994
|
+
"useClient.ts": "./__client/_useClient",
|
|
995
|
+
"st.ts": "./__client/_st",
|
|
996
|
+
});
|
|
997
|
+
expect(sorted(await evaluateBoth())).toEqual(sorted(whole));
|
|
998
|
+
}, 120_000);
|
|
999
|
+
});
|
|
1000
|
+
|
|
1001
|
+
const redeclaringLibStore = `import { store } from "akanjs/store";
|
|
1002
|
+
|
|
1003
|
+
import { sig } from "../useClient";
|
|
1004
|
+
|
|
1005
|
+
export class ItemStore extends store(sig.item, () => ({ itemCount: 1, tally: 0, winner: "" })) {
|
|
1006
|
+
static side = "lib";
|
|
1007
|
+
markWinner() {
|
|
1008
|
+
this.set({ winner: "lib" });
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
`;
|
|
1012
|
+
const redeclaringAppStore = `import { store } from "akanjs/store";
|
|
1013
|
+
|
|
1014
|
+
import { item } from "../__lib/lib.store";
|
|
1015
|
+
import { sig } from "../useClient";
|
|
1016
|
+
|
|
1017
|
+
export class ItemStore extends store(sig.item, () => ({ itemCount: 10, noteDraft: "" }), ...item.stores) {
|
|
1018
|
+
static side = "app";
|
|
1019
|
+
markWinner() {
|
|
1020
|
+
this.set({ winner: "app" });
|
|
1021
|
+
}
|
|
1022
|
+
setTally(tally: number) {
|
|
1023
|
+
this.set({ tally: tally * 2 });
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
`;
|
|
1027
|
+
const browserGlobals =
|
|
1028
|
+
'Object.assign(globalThis, { window: globalThis, location: new URL("http://localhost:4200/") });';
|
|
1029
|
+
const redeclaredScript = (files: string[], { browser = false } = {}) => `
|
|
1030
|
+
${browser ? browserGlobals : ""}
|
|
1031
|
+
${files.map((file) => `await import("./${file}");`).join("\n")}
|
|
1032
|
+
const { instance: st, store } = globalThis[Symbol.for("akanjs.store.registry")];
|
|
1033
|
+
const itemCount = st.get().itemCount;
|
|
1034
|
+
await st.do.markWinner();
|
|
1035
|
+
await st.do.setTally(3);
|
|
1036
|
+
console.log(JSON.stringify({
|
|
1037
|
+
default: itemCount,
|
|
1038
|
+
action: st.get().winner,
|
|
1039
|
+
setter: st.get().tally,
|
|
1040
|
+
generatedSetter: st.generatedSetters.has("setTally"),
|
|
1041
|
+
registered: store.get("item").side,
|
|
1042
|
+
}));
|
|
1043
|
+
`;
|
|
1044
|
+
const keptValueScript = (pieces: string, wholes: string, itemCount: number) => `
|
|
1045
|
+
${browserGlobals}
|
|
1046
|
+
await import("./${pieces}");
|
|
1047
|
+
const st = globalThis[Symbol.for("akanjs.store.registry")].instance;
|
|
1048
|
+
await st.do.setItemCount(${itemCount});
|
|
1049
|
+
await st.do.setNoteDraft("typed");
|
|
1050
|
+
await st.do.setTally(4);
|
|
1051
|
+
await import("./${wholes}");
|
|
1052
|
+
const { itemCount, noteDraft, tally } = st.get();
|
|
1053
|
+
console.log(JSON.stringify({ itemCount, noteDraft, tally }));
|
|
1054
|
+
`;
|
|
1055
|
+
const pickingLibStore = `import { store } from "akanjs/store";
|
|
1056
|
+
|
|
1057
|
+
import { fetch, sig } from "../useClient";
|
|
1058
|
+
|
|
1059
|
+
export class ItemStore extends store(sig.item, () => ({ itemCount: 1, picked: "" })) {
|
|
1060
|
+
pick(name: string) {
|
|
1061
|
+
this.set({ picked: typeof (fetch as unknown as Record<string, unknown>)[name] });
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
`;
|
|
1065
|
+
const pickedScript = (files: string[], { browser = false } = {}) => `
|
|
1066
|
+
${browser ? browserGlobals : ""}
|
|
1067
|
+
${files.map((file) => `await import("./${file}");`).join("\n")}
|
|
1068
|
+
const st = globalThis[Symbol.for("akanjs.store.registry")].instance;
|
|
1069
|
+
await st.do.pick("pingAt");
|
|
1070
|
+
console.log(JSON.stringify({ picked: st.get().picked, otherStore: typeof st.do.pickLabel, own: typeof st.do.setTally }));
|
|
1071
|
+
`;
|
|
1072
|
+
const writeRedeclaringWorkspace = (app: string, lib: string, libStore = redeclaringLibStore) =>
|
|
1073
|
+
writeWorkspace({
|
|
1074
|
+
app,
|
|
1075
|
+
lib,
|
|
1076
|
+
libFiles: {
|
|
1077
|
+
...stockFiles,
|
|
1078
|
+
"lib/item/item.store.ts": libStore,
|
|
1079
|
+
"ui/Picker.tsx": `import { st } from "@libs/${lib}/client";
|
|
1080
|
+
export const Picker = (name: string) => (st.do as unknown as Record<string, () => void>)[name]?.();
|
|
1081
|
+
`,
|
|
1082
|
+
},
|
|
1083
|
+
appFiles: {
|
|
1084
|
+
...shopFilesOf(lib),
|
|
1085
|
+
"lib/item/item.store.ts": redeclaringAppStore,
|
|
1086
|
+
"ui/Count.tsx": `import { st } from "@apps/${app}/client";\nexport const Count = () => st.use.itemCount();\n`,
|
|
1087
|
+
"ui/Field.tsx": 'import "../../../node_modules/akanjs/ui/modelRuntime";\nexport const Field = () => null;\n',
|
|
1088
|
+
},
|
|
1089
|
+
});
|
|
1090
|
+
//? Written outside the app and the lib, where the build reads no import: only the files an entry loads are rewritten.
|
|
1091
|
+
const writeLoadOrder = async (root: string, name: string, pieces: string[]) => {
|
|
1092
|
+
await writeText(path.join(root, `orders/${name}.ts`), pieces.map((piece) => `import "@${piece}";\n`).join(""));
|
|
1093
|
+
return `orders/${name}.ts`;
|
|
1094
|
+
};
|
|
1095
|
+
|
|
1096
|
+
describe("an app store that redeclares what the lib store it extends declares", () => {
|
|
1097
|
+
const wholeAnswer = { default: 1, action: "app", setter: 6, generatedSetter: true, registered: "app" };
|
|
1098
|
+
|
|
1099
|
+
test("answers under every load order of its pieces, each built as a page loads them, what the whole runtime answers: the lib's default, its own action and its own declared setter", async () => {
|
|
1100
|
+
const [app, lib] = ["grocer", "silo"];
|
|
1101
|
+
const temp = await writeRedeclaringWorkspace(app, lib);
|
|
1102
|
+
const { root } = temp;
|
|
1103
|
+
const [appPiece, libPiece] = [`apps/${app}/lib/__client/item.st`, `libs/${lib}/lib/__client/item.st`];
|
|
1104
|
+
const [appWhole, libWhole] = [`apps/${app}/lib/__client/_st`, `libs/${lib}/lib/__client/_st`];
|
|
1105
|
+
const libStore = `libs/${lib}/lib/st`;
|
|
1106
|
+
const orders = [[libPiece, appPiece], [appPiece, libPiece], [appPiece, libWhole, appWhole], [libStore], [appWhole]];
|
|
1107
|
+
|
|
1108
|
+
expect(await evaluate(root, redeclaredScript([`apps/${app}/lib/st.ts`]), app)).toEqual(wholeAnswer);
|
|
1109
|
+
for (const [index, order] of orders.entries()) {
|
|
1110
|
+
const { pages } = await bundleForBrowser(temp.root, app, [await writeLoadOrder(root, `order${index}`, order)]);
|
|
1111
|
+
const answer = await evaluate(root, redeclaredScript(pages, { browser: true }), app);
|
|
1112
|
+
expect({ order, answer }).toEqual({ order, answer: wholeAnswer });
|
|
1113
|
+
}
|
|
1114
|
+
}, 240_000);
|
|
1115
|
+
|
|
1116
|
+
test("answers in a page's own bundle what the whole runtime answers, whether the page first reaches a lib file picking its action at run time, a framework component reaching models by name, or the store's own name", async () => {
|
|
1117
|
+
const [app, lib] = ["florist", "cellar"];
|
|
1118
|
+
const temp = await writeRedeclaringWorkspace(app, lib);
|
|
1119
|
+
for (const page of [`libs/${lib}/ui/Picker.tsx`, `apps/${app}/ui/Field.tsx`, `apps/${app}/ui/Count.tsx`]) {
|
|
1120
|
+
const { pages } = await bundleForBrowser(temp.root, app, [page]);
|
|
1121
|
+
const answer = await evaluate(temp.root, redeclaredScript(pages, { browser: true }), app);
|
|
1122
|
+
expect({ page, answer }).toEqual({ page, answer: wholeAnswer });
|
|
1123
|
+
}
|
|
1124
|
+
}, 240_000);
|
|
1125
|
+
|
|
1126
|
+
test("loads every model's runtime with a lib store that picks an endpoint at run time, in each page whose client code names that store or the app store extending it", async () => {
|
|
1127
|
+
const [app, lib] = ["tailor", "attic"];
|
|
1128
|
+
const temp = await writeRedeclaringWorkspace(app, lib, pickingLibStore);
|
|
1129
|
+
const { root } = temp;
|
|
1130
|
+
const whole = await evaluate(root, pickedScript([`apps/${app}/lib/st.ts`]), app);
|
|
1131
|
+
expect(whole).toEqual({ picked: "function", otherStore: "function", own: "function" });
|
|
1132
|
+
for (const page of [`apps/${app}/ui/Count.tsx`, `libs/${lib}/ui/Picker.tsx`, `apps/${app}/ui/Field.tsx`]) {
|
|
1133
|
+
const { pages } = await bundleForBrowser(temp.root, app, [page]);
|
|
1134
|
+
const answer = await evaluate(root, pickedScript(pages, { browser: true }), app);
|
|
1135
|
+
expect({ page, answer }).toEqual({ page, answer: whole });
|
|
1136
|
+
}
|
|
1137
|
+
}, 240_000);
|
|
1138
|
+
|
|
1139
|
+
test("keeps a value set by hand when the whole runtime loads after its pieces, whichever declared default the value equals", async () => {
|
|
1140
|
+
const [app, lib] = ["baker", "larder"];
|
|
1141
|
+
const temp = await writeRedeclaringWorkspace(app, lib);
|
|
1142
|
+
const { root } = temp;
|
|
1143
|
+
const { pages } = await bundleForBrowser(temp.root, app, [
|
|
1144
|
+
await writeLoadOrder(root, "pieces", [`libs/${lib}/lib/__client/item.st`, `apps/${app}/lib/__client/item.st`]),
|
|
1145
|
+
await writeLoadOrder(root, "wholes", [`libs/${lib}/lib/__client/_st`, `apps/${app}/lib/__client/_st`]),
|
|
1146
|
+
]);
|
|
1147
|
+
const [pieces, wholes] = ["pieces", "wholes"].map((name) => `${pages.find((page) => page.endsWith(`${name}.js`))}`);
|
|
1148
|
+
for (const itemCount of [1, 10, 5])
|
|
1149
|
+
expect(await evaluate(root, keptValueScript(pieces, wholes, itemCount), app)).toEqual({
|
|
1150
|
+
itemCount,
|
|
1151
|
+
noteDraft: "typed",
|
|
1152
|
+
tally: 8,
|
|
1153
|
+
});
|
|
1154
|
+
}, 120_000);
|
|
1155
|
+
});
|
|
1156
|
+
|
|
1157
|
+
const indirectFilesOf = (app: string): Record<string, string> => ({
|
|
1158
|
+
"lib/_note/note.store.ts": `import { store } from "akanjs/store";
|
|
1159
|
+
|
|
1160
|
+
export class NoteStore extends store("note" as const, () => ({ noteText: "memo" })) {
|
|
1161
|
+
static both({ noteText, label }: { noteText: string; label: string }) {
|
|
1162
|
+
return [noteText, label].join("|");
|
|
1163
|
+
}
|
|
1164
|
+
showBoth() {
|
|
1165
|
+
this.set({ noteText: NoteStore.both(this.get() as never) });
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
`,
|
|
1169
|
+
"ui/Cast.tsx": `import { st } from "@apps/${app}/client";
|
|
1170
|
+
const get = st.get as unknown as <T>() => { [key: string]: T };
|
|
1171
|
+
export const read = () => [(st.get() as unknown as { label: string }).label, get<string>().label];
|
|
1172
|
+
`,
|
|
1173
|
+
"ui/Asserted.tsx": `import { st } from "@apps/${app}/client";
|
|
1174
|
+
export const read = (key: string) => st.get()[key as "itemCount"];
|
|
1175
|
+
`,
|
|
1176
|
+
"ui/Built.tsx": `import { capitalize } from "akanjs/common";
|
|
1177
|
+
import type { SliceMeta } from "akanjs/fetch";
|
|
1178
|
+
import { st } from "@apps/${app}/client";
|
|
1179
|
+
export const read = (slice: SliceMeta) =>
|
|
1180
|
+
(st.get() as unknown as { [key: string]: unknown })[\`limitOf\${capitalize(slice.sliceName)}\`];
|
|
1181
|
+
`,
|
|
1182
|
+
"ui/Named.tsx": `import { fetch } from "@apps/${app}/client";\nexport const slice = fetch.slice.itemInPublic;\n`,
|
|
1183
|
+
"ui/Written.tsx": 'export const slice = { refName: "item", sliceName: "itemInPublic", argLength: 0 };\n',
|
|
1184
|
+
"ui/Handed.tsx": `import { st } from "@apps/${app}/client";
|
|
1185
|
+
export const read = async () => {
|
|
1186
|
+
await st.do.showBoth();
|
|
1187
|
+
return (st.get() as unknown as { noteText: string }).noteText;
|
|
1188
|
+
};
|
|
1189
|
+
`,
|
|
1190
|
+
"ui/Screen.tsx": `import { ScreenSettle } from "akanjs/store/agent";
|
|
1191
|
+
import { st } from "@apps/${app}/client";
|
|
1192
|
+
export const read = () => [typeof ScreenSettle, (st.get() as unknown as { label: string }).label];
|
|
1193
|
+
`,
|
|
1194
|
+
});
|
|
1195
|
+
const indirectScript = (pages: string[], body: string) => `
|
|
1196
|
+
${browserGlobals}
|
|
1197
|
+
const fileOf = (name) => "./" + ${JSON.stringify(pages)}.find((page) => page.endsWith(name + ".js"));
|
|
1198
|
+
const stores = () => {
|
|
1199
|
+
const st = globalThis[Symbol.for("akanjs.store.registry")]?.instance;
|
|
1200
|
+
return ["setLabel", "setNoteText", "setItemCount"].map((name) => typeof st?.do?.[name] === "function");
|
|
1201
|
+
};
|
|
1202
|
+
${body}
|
|
1203
|
+
`;
|
|
1204
|
+
const wholeIndirectScript = (app: string) => `
|
|
1205
|
+
await import("./apps/${app}/lib/st.ts");
|
|
1206
|
+
const st = globalThis[Symbol.for("akanjs.store.registry")].instance;
|
|
1207
|
+
const { label, itemCount, limitOfItemInPublic } = st.get();
|
|
1208
|
+
await st.do.showBoth();
|
|
1209
|
+
console.log(JSON.stringify({ label, itemCount, limitOfItemInPublic, noteText: st.get().noteText }));
|
|
1210
|
+
`;
|
|
1211
|
+
|
|
1212
|
+
describe("a page reaching a store only by an indirect read", () => {
|
|
1213
|
+
const [app, lib] = ["atelier", "trunk"];
|
|
1214
|
+
let workspace: ReturnType<typeof writeWorkspace> | null = null;
|
|
1215
|
+
const built = async (entries: string[]) => {
|
|
1216
|
+
workspace ??= writeWorkspace({
|
|
1217
|
+
app,
|
|
1218
|
+
lib,
|
|
1219
|
+
libFiles: stockFiles,
|
|
1220
|
+
appFiles: { ...shopFilesOf(lib), ...indirectFilesOf(app) },
|
|
1221
|
+
kept: true,
|
|
1222
|
+
});
|
|
1223
|
+
const { root } = await workspace;
|
|
1224
|
+
const whole = await evaluate(root, wholeIndirectScript(app), app);
|
|
1225
|
+
const { pages } = await bundleForBrowser(root, app, entries);
|
|
1226
|
+
return { whole, run: (body: string) => evaluate(root, indirectScript(pages, body), app) };
|
|
1227
|
+
};
|
|
1228
|
+
const onlyStore = (index: number) => [0, 1, 2].map((at) => at === index);
|
|
1229
|
+
afterAll(async () => {
|
|
1230
|
+
if (workspace) await rm((await workspace).root, { recursive: true, force: true });
|
|
1231
|
+
});
|
|
1232
|
+
|
|
1233
|
+
test("answers a name read through a cast, through a store read taken off the store, and by a key asserted as a name, with that name's store alone", async () => {
|
|
1234
|
+
const { whole, run } = await built([`apps/${app}/ui/Cast.tsx`]);
|
|
1235
|
+
expect(whole).toEqual({ label: expect.any(String), itemCount: 0, limitOfItemInPublic: 20, noteText: "memo|kit" });
|
|
1236
|
+
expect(
|
|
1237
|
+
await run('console.log(JSON.stringify({ read: (await import(fileOf("Cast"))).read(), stores: stores() }));'),
|
|
1238
|
+
).toEqual({ read: [whole.label, whole.label], stores: onlyStore(0) });
|
|
1239
|
+
const asserted = await built([`apps/${app}/ui/Asserted.tsx`]);
|
|
1240
|
+
expect(
|
|
1241
|
+
await asserted.run(
|
|
1242
|
+
'console.log(JSON.stringify({ read: (await import(fileOf("Asserted"))).read("itemCount"), stores: stores() }));',
|
|
1243
|
+
),
|
|
1244
|
+
).toEqual({ read: whole.itemCount, stores: onlyStore(2) });
|
|
1245
|
+
}, 240_000);
|
|
1246
|
+
|
|
1247
|
+
test("answers a name built from a handed slice once the slice's model arrived, by its reference, by the file naming it or by the file writing it out, and loads no model itself", async () => {
|
|
1248
|
+
const read = (slice: string) => `
|
|
1249
|
+
const page = await import(fileOf("Built"));
|
|
1250
|
+
const before = stores();
|
|
1251
|
+
const slice = ${slice};
|
|
1252
|
+
console.log(JSON.stringify({ before, read: page.read(slice), after: stores() }));
|
|
1253
|
+
`;
|
|
1254
|
+
const handed = '{ refName: "item", sliceName: "itemInPublic", argLength: 0 }';
|
|
1255
|
+
const arrivals = [
|
|
1256
|
+
{ entry: `apps/${app}/lib/__client/item.ref.ts`, slice: `(await import(fileOf("item.ref")), ${handed})` },
|
|
1257
|
+
{ entry: `apps/${app}/ui/Named.tsx`, slice: '(await import(fileOf("Named"))).slice' },
|
|
1258
|
+
{ entry: `apps/${app}/ui/Written.tsx`, slice: '(await import(fileOf("Written"))).slice' },
|
|
1259
|
+
];
|
|
1260
|
+
for (const { entry, slice } of arrivals) {
|
|
1261
|
+
const { whole, run } = await built([`apps/${app}/ui/Built.tsx`, entry]);
|
|
1262
|
+
expect({ entry, answer: await run(read(slice)) }).toEqual({
|
|
1263
|
+
entry,
|
|
1264
|
+
answer: { before: onlyStore(-1), read: whole.limitOfItemInPublic, after: onlyStore(2) },
|
|
1265
|
+
});
|
|
1266
|
+
}
|
|
1267
|
+
}, 360_000);
|
|
1268
|
+
|
|
1269
|
+
test("answers the names a function of the store's file reads from the state it is handed, and a page importing the agent's screen classes, with the stores they name alone", async () => {
|
|
1270
|
+
const { whole, run } = await built([`apps/${app}/ui/Handed.tsx`]);
|
|
1271
|
+
expect(
|
|
1272
|
+
await run(
|
|
1273
|
+
'console.log(JSON.stringify({ read: await (await import(fileOf("Handed"))).read(), stores: stores() }));',
|
|
1274
|
+
),
|
|
1275
|
+
).toEqual({ read: whole.noteText, stores: [true, true, false] });
|
|
1276
|
+
const screen = await built([`apps/${app}/ui/Screen.tsx`]);
|
|
1277
|
+
expect(
|
|
1278
|
+
await screen.run(
|
|
1279
|
+
'console.log(JSON.stringify({ read: (await import(fileOf("Screen"))).read(), stores: stores() }));',
|
|
1280
|
+
),
|
|
1281
|
+
).toEqual({ read: ["function", whole.label], stores: onlyStore(0) });
|
|
1282
|
+
}, 240_000);
|
|
1283
|
+
});
|
|
1284
|
+
|
|
1285
|
+
const noticeStore = `import { store } from "akanjs/store";
|
|
1286
|
+
|
|
1287
|
+
export class NoticeStore extends store("notice" as const, () => ({ noticeCount: 0, noticeText: "" })) {
|
|
1288
|
+
applyNotice(patch: { noticeCount?: number; noticeText?: string }) {
|
|
1289
|
+
this.set({ ...patch });
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
`;
|
|
1293
|
+
const orgStoreOf = (lib: string) => `import { kitLabel } from "@libs/${lib}/common";
|
|
1294
|
+
import { store } from "akanjs/store";
|
|
1295
|
+
|
|
1296
|
+
import { st } from "../st";
|
|
1297
|
+
import { fetch, sig } from "../useClient";
|
|
1298
|
+
|
|
1299
|
+
export class OrgStore extends store(sig.org, () => ({ orgCount: 0, orgLabel: kitLabel })) {
|
|
1300
|
+
async refreshOrgCount() {
|
|
1301
|
+
this.set({ orgCount: await fetch.orgCount() });
|
|
1302
|
+
st.do.applyNotice({ noticeText: "org" });
|
|
1303
|
+
st.do.callCrew();
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
`;
|
|
1307
|
+
const crewStore = `import { store } from "akanjs/store";
|
|
1308
|
+
|
|
1309
|
+
import { st } from "../st";
|
|
1310
|
+
|
|
1311
|
+
export class CrewStore extends store("crew" as const, () => ({ crewCalls: 0 })) {
|
|
1312
|
+
callCrew() {
|
|
1313
|
+
this.set({ crewCalls: st.get().orgCount });
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
`;
|
|
1317
|
+
const emptyServiceDictionary = `import { serviceDictionary } from "akanjs/dictionary";
|
|
1318
|
+
|
|
1319
|
+
export const dictionary = serviceDictionary(["en", "ko"]).translate({});
|
|
1320
|
+
`;
|
|
1321
|
+
|
|
1322
|
+
//? Three scopes shaped like a workspace that failed: a lib store spreading into \`this.set\` that another lib's store
|
|
1323
|
+
//? uses, two stores naming each other, and a store reached by fewer entries than its model's fetch piece.
|
|
1324
|
+
const writeHarborWorkspace = (
|
|
1325
|
+
app: string,
|
|
1326
|
+
base: string,
|
|
1327
|
+
upper: string,
|
|
1328
|
+
moreAppFiles: Record<string, string> = {},
|
|
1329
|
+
moreUpperFiles: Record<string, string> = {},
|
|
1330
|
+
) =>
|
|
1331
|
+
writeWorkspace({
|
|
1332
|
+
app,
|
|
1333
|
+
lib: base,
|
|
1334
|
+
libFiles: {
|
|
1335
|
+
...stockFiles,
|
|
1336
|
+
"lib/_notice/notice.dictionary.ts": emptyServiceDictionary,
|
|
1337
|
+
"lib/_notice/notice.store.ts": noticeStore,
|
|
1338
|
+
},
|
|
1339
|
+
moreLibs: {
|
|
1340
|
+
[upper]: {
|
|
1341
|
+
"lib/option.ts": option,
|
|
1342
|
+
...kitModuleNamed("org", "Org"),
|
|
1343
|
+
"lib/org/org.store.ts": orgStoreOf(base),
|
|
1344
|
+
"lib/_crew/crew.dictionary.ts": emptyServiceDictionary,
|
|
1345
|
+
"lib/_crew/crew.store.ts": crewStore,
|
|
1346
|
+
...moreUpperFiles,
|
|
1347
|
+
},
|
|
1348
|
+
},
|
|
1349
|
+
appFiles: {
|
|
1350
|
+
...shopFilesOf(base),
|
|
1351
|
+
"ui/Count.tsx": `import { st } from "@apps/${app}/client";\nexport const Count = () => st.use.itemCount();\n`,
|
|
1352
|
+
"ui/Note.tsx": `import { fetch } from "@apps/${app}/client";\nexport const Note = () => fetch.itemNote();\n`,
|
|
1353
|
+
"ui/Org.tsx": `import { st } from "@libs/${upper}/client";\nexport const Org = () => st.use.orgCount();\n`,
|
|
1354
|
+
"ui/Both.tsx": `import { st } from "@apps/${app}/client";\nexport const Both = () => [st.use.itemCount(), st.use.orgCount()];\n`,
|
|
1355
|
+
...moreAppFiles,
|
|
1356
|
+
},
|
|
1357
|
+
});
|
|
1358
|
+
|
|
1359
|
+
interface RouteBuilt {
|
|
1360
|
+
failure: string | null;
|
|
1361
|
+
warnings: string[];
|
|
1362
|
+
wholeRuntimeEntries: string[];
|
|
1363
|
+
chunksLeftFromEarlierBundles: string[];
|
|
1364
|
+
storeChunks: string[];
|
|
1365
|
+
fetchPieceChunks: string[];
|
|
1366
|
+
storePiecesStoresImport: string[];
|
|
1367
|
+
storesBesideOrg: string[];
|
|
1368
|
+
storeFilesByEntry: Record<string, string[]>;
|
|
1369
|
+
constantsByEntry: Record<string, string[]>;
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
const routeBuildScript = (
|
|
1373
|
+
root: string,
|
|
1374
|
+
appName: string,
|
|
1375
|
+
entries: string[],
|
|
1376
|
+
store: string,
|
|
1377
|
+
fetchPiece: string,
|
|
1378
|
+
routes?: Record<string, string[]>,
|
|
1379
|
+
) => `
|
|
1380
|
+
const path = await import("node:path");
|
|
1381
|
+
const { AppExecutor } = await import(${devkitFile("executors/appExecutor.ts")});
|
|
1382
|
+
const { WorkspaceExecutor } = await import(${devkitFile("executors/workspaceExecutor.ts")});
|
|
1383
|
+
const { ClientEntriesBundler } = await import(${devkitFile("frontendBuild/clientEntriesBundler.ts")});
|
|
1384
|
+
const { RouteClientBuilder } = await import(${devkitFile("frontendBuild/routeClientBuilder.ts")});
|
|
1385
|
+
const [root, appName, entries, store, fetchPiece, routes] = ${JSON.stringify([root, appName, entries, store, fetchPiece, routes ?? null])};
|
|
1386
|
+
const app = AppExecutor.from(new WorkspaceExecutor({ workspaceRoot: root, repoName: "repo" }), appName);
|
|
1387
|
+
const graphs = [];
|
|
1388
|
+
const bundle = ClientEntriesBundler.prototype.bundle;
|
|
1389
|
+
ClientEntriesBundler.prototype.bundle = async function () {
|
|
1390
|
+
const result = await bundle.call(this);
|
|
1391
|
+
graphs.push(result.graph);
|
|
1392
|
+
return result;
|
|
1393
|
+
};
|
|
1394
|
+
let failure = null;
|
|
1395
|
+
const warnings = [];
|
|
1396
|
+
app.logger.warn = (message) => {
|
|
1397
|
+
warnings.push(message);
|
|
1398
|
+
};
|
|
1399
|
+
await new RouteClientBuilder({
|
|
1400
|
+
app,
|
|
1401
|
+
seeds: [],
|
|
1402
|
+
entries: entries.map((entry) => path.join(root, entry)),
|
|
1403
|
+
artifact: {},
|
|
1404
|
+
browser: "chunks",
|
|
1405
|
+
...(routes
|
|
1406
|
+
? { entriesByRoute: new Map(Object.entries(routes).map(([route, held]) => [route, held.map((entry) => path.join(root, entry))])) }
|
|
1407
|
+
: {}),
|
|
1408
|
+
})
|
|
1409
|
+
.build()
|
|
1410
|
+
.catch((error) => {
|
|
1411
|
+
failure = error.message;
|
|
1412
|
+
});
|
|
1413
|
+
const measuredAgainst = (graph) => [...graph.chunksByModule.values()].flat().some((chunk) => chunk.split(path.sep).includes("client-whole"));
|
|
1414
|
+
const browser = graphs.filter((graph) => !measuredAgainst(graph)).at(-1);
|
|
1415
|
+
const earlierChunks = graphs.filter((graph) => graph !== browser).flatMap((graph) => [...graph.importsByChunk.keys()]);
|
|
1416
|
+
const chunksLeft = [];
|
|
1417
|
+
for (const chunk of new Set(earlierChunks))
|
|
1418
|
+
if (!chunk.split(path.sep).includes("client-ssr") && !browser.importsByChunk.has(chunk) && (await Bun.file(chunk).exists()))
|
|
1419
|
+
chunksLeft.push(path.basename(chunk));
|
|
1420
|
+
const nameOf = (file) => path.relative(root, file);
|
|
1421
|
+
const chunksOf = (file) => (browser.chunksByModule.get(path.join(root, file)) ?? []).map((chunk) => path.basename(chunk));
|
|
1422
|
+
const importsOf = (file) => (browser.importsByModule.get(file) ?? []).map((imported) => nameOf(imported.path));
|
|
1423
|
+
const storeFiles = [...browser.importsByModule.keys()].filter((file) => file.endsWith(".store.ts"));
|
|
1424
|
+
const reachedBy = (entry) => {
|
|
1425
|
+
const reached = new Set([...browser.importsByModule.keys()].filter((file) => importsOf(file).includes(entry)));
|
|
1426
|
+
for (const file of reached)
|
|
1427
|
+
for (const imported of browser.importsByModule.get(file) ?? []) if (!imported.lazy) reached.add(imported.path);
|
|
1428
|
+
return [...reached].map(nameOf);
|
|
1429
|
+
};
|
|
1430
|
+
const storeFilesOf = (entry) => reachedBy(entry).filter((file) => file.endsWith(".store.ts")).sort();
|
|
1431
|
+
const constantsOf = (entry) => reachedBy(entry).filter((file) => file.endsWith("/lib/cnst.ts")).sort();
|
|
1432
|
+
console.log(JSON.stringify({
|
|
1433
|
+
failure,
|
|
1434
|
+
warnings,
|
|
1435
|
+
wholeRuntimeEntries: entries.filter((entry) => reachedBy(entry).some((file) => /\\/lib\\/(st|useClient)\\.ts$/.test(file))),
|
|
1436
|
+
chunksLeftFromEarlierBundles: chunksLeft,
|
|
1437
|
+
storeChunks: chunksOf(store),
|
|
1438
|
+
fetchPieceChunks: chunksOf(fetchPiece),
|
|
1439
|
+
storePiecesStoresImport: storeFiles.flatMap(importsOf).filter((file) => /__client\\/[^_/][^/]*\\.st\\.ts$/.test(file)),
|
|
1440
|
+
storesBesideOrg: [...browser.importsByModule.keys()].map(nameOf).filter((file) => /__client\\/[^_/][^/]*\\.st\\.ts$/.test(file)).sort(),
|
|
1441
|
+
storeFilesByEntry: Object.fromEntries(entries.map((entry) => [entry, storeFilesOf(entry)])),
|
|
1442
|
+
constantsByEntry: Object.fromEntries(entries.map((entry) => [entry, constantsOf(entry)])),
|
|
1443
|
+
}));
|
|
1444
|
+
`;
|
|
1445
|
+
|
|
1446
|
+
describe("a build of a three-scope workspace", () => {
|
|
1447
|
+
test("passes its own check with a store and its model's fetch piece in different chunks, a file two entries share apart from the store piece it names, a lib store spreading into `this.set` and two stores naming each other, no store file importing a store piece", async () => {
|
|
1448
|
+
const [app, base, upper] = ["harbor", "berth", "jetty"];
|
|
1449
|
+
const temp = await writeHarborWorkspace(app, base, upper, {
|
|
1450
|
+
"ui/Tally.tsx": `import { st } from "@apps/${app}/client";\nexport const tally = () => st.use.itemCount();\n`,
|
|
1451
|
+
"ui/Wide.tsx": `import { tally } from "./Tally";\nexport const Wide = () => tally;\n`,
|
|
1452
|
+
"ui/Org.tsx": `import { st } from "@libs/${upper}/client";\nimport { tally } from "./Tally";\nexport const Org = () => [st.use.orgCount(), tally];\n`,
|
|
1453
|
+
});
|
|
1454
|
+
const entries = ["Count", "Note", "Org", "Both", "Wide"].map((name) => `apps/${app}/ui/${name}.tsx`);
|
|
1455
|
+
const built = (await evaluate(
|
|
1456
|
+
temp.root,
|
|
1457
|
+
routeBuildScript(
|
|
1458
|
+
temp.root,
|
|
1459
|
+
app,
|
|
1460
|
+
entries,
|
|
1461
|
+
`apps/${app}/lib/item/item.store.ts`,
|
|
1462
|
+
`apps/${app}/lib/__client/item.fetch.ts`,
|
|
1463
|
+
),
|
|
1464
|
+
app,
|
|
1465
|
+
)) as unknown as RouteBuilt;
|
|
1466
|
+
expect(built.failure).toBeNull();
|
|
1467
|
+
expect(built.warnings).toEqual([]);
|
|
1468
|
+
expect(built.wholeRuntimeEntries).toEqual([]);
|
|
1469
|
+
expect(built.storeChunks).toHaveLength(1);
|
|
1470
|
+
expect(built.fetchPieceChunks).toHaveLength(1);
|
|
1471
|
+
expect(built.storeChunks).not.toEqual(built.fetchPieceChunks);
|
|
1472
|
+
expect(built.storePiecesStoresImport).toEqual([]);
|
|
1473
|
+
expect(built.storesBesideOrg).toEqual([
|
|
1474
|
+
`apps/${app}/lib/__client/item.st.ts`,
|
|
1475
|
+
`libs/${base}/lib/__client/item.st.ts`,
|
|
1476
|
+
`libs/${base}/lib/__client/notice.st.ts`,
|
|
1477
|
+
`libs/${upper}/lib/__client/crew.st.ts`,
|
|
1478
|
+
`libs/${upper}/lib/__client/org.st.ts`,
|
|
1479
|
+
]);
|
|
1480
|
+
}, 240_000);
|
|
1481
|
+
|
|
1482
|
+
test("warns once, naming both files, where a file imports a runtime piece only for its effect and the build splits the two apart, then builds every page on the whole runtime and leaves no chunk of the refused build", async () => {
|
|
1483
|
+
const [app, base, upper] = ["pier", "shed", "dock"];
|
|
1484
|
+
const temp = await writeHarborWorkspace(app, base, upper, {
|
|
1485
|
+
"ui/Count.tsx": `import { st } from "@apps/${app}/client";\nimport { hand } from "../../../shared/hand";\nexport const Count = () => [st.use.itemCount(), hand];\n`,
|
|
1486
|
+
"ui/Org.tsx": `import { st } from "@libs/${upper}/client";\nimport { hand } from "../../../shared/hand";\nexport const Org = () => [st.use.orgCount(), hand];\n`,
|
|
1487
|
+
});
|
|
1488
|
+
await writeText(
|
|
1489
|
+
path.join(temp.root, "shared/hand.ts"),
|
|
1490
|
+
`import "@apps/${app}/lib/__client/item.fetch";\nexport const hand = "hand";\n`,
|
|
1491
|
+
);
|
|
1492
|
+
const entries = ["Count", "Note", "Org", "Both"].map((name) => `apps/${app}/ui/${name}.tsx`);
|
|
1493
|
+
const built = (await evaluate(
|
|
1494
|
+
temp.root,
|
|
1495
|
+
routeBuildScript(temp.root, app, entries, "shared/hand.ts", `apps/${app}/lib/__client/item.fetch.ts`),
|
|
1496
|
+
app,
|
|
1497
|
+
)) as unknown as RouteBuilt;
|
|
1498
|
+
expect(built.failure).toBeNull();
|
|
1499
|
+
expect(built.warnings).toHaveLength(1);
|
|
1500
|
+
expect(built.warnings[0]?.split("\n")).toEqual([
|
|
1501
|
+
"[client-runtime] loading per module, this build would not load its modules in order:",
|
|
1502
|
+
expect.stringMatching(
|
|
1503
|
+
new RegExp(
|
|
1504
|
+
`^ - shared/hand\\.ts needs apps/${app}/lib/__client/item\\.fetch\\.ts loaded first, but its chunk \\S+\\.js does not import the chunk holding that piece$`,
|
|
1505
|
+
),
|
|
1506
|
+
),
|
|
1507
|
+
"Every page of this build loads the whole client runtime instead, not only what it uses. This is a bug in akan: report it with the lines above.",
|
|
1508
|
+
]);
|
|
1509
|
+
expect(built.wholeRuntimeEntries).toEqual(entries);
|
|
1510
|
+
expect(built.chunksLeftFromEarlierBundles).toEqual([]);
|
|
1511
|
+
expect(await Bun.file(path.join(temp.root, `apps/${app}/.akan/cache/route-runtime.json`)).exists()).toBe(false);
|
|
1512
|
+
}, 240_000);
|
|
1513
|
+
|
|
1514
|
+
test("passes its own check where an entry no route holds names a model whose constant file reads another lib's constants from that lib's barrel, and loads every constant there and none of that lib's in a route's page", async () => {
|
|
1515
|
+
const [app, base, upper] = ["ferry", "winch", "barge"];
|
|
1516
|
+
const orgConstant = kitModuleNamed("org", "Org")["lib/org/org.constant.ts"] ?? "";
|
|
1517
|
+
const temp = await writeHarborWorkspace(
|
|
1518
|
+
app,
|
|
1519
|
+
base,
|
|
1520
|
+
upper,
|
|
1521
|
+
{},
|
|
1522
|
+
{
|
|
1523
|
+
"lib/org/org.constant.ts": `import { cnst as ${base} } from "@libs/${base}";\n${orgConstant}\nexport const orgKinds = [${base}.Item.name];\n`,
|
|
1524
|
+
"lib/org/org.store.ts": orgStoreOf(base)
|
|
1525
|
+
.replace('import { st } from "../st";', 'import * as cnst from "../cnst";\nimport { st } from "../st";')
|
|
1526
|
+
.replace("orgLabel: kitLabel", "orgLabel: kitLabel + cnst.Org.name"),
|
|
1527
|
+
},
|
|
1528
|
+
);
|
|
1529
|
+
const [count, note, org] = ["Count", "Note", "Org"].map((name) => `apps/${app}/ui/${name}.tsx`);
|
|
1530
|
+
const built = (await evaluate(
|
|
1531
|
+
temp.root,
|
|
1532
|
+
routeBuildScript(
|
|
1533
|
+
temp.root,
|
|
1534
|
+
app,
|
|
1535
|
+
[count, note, org],
|
|
1536
|
+
`libs/${upper}/lib/org/org.store.ts`,
|
|
1537
|
+
`apps/${app}/lib/__client/item.fetch.ts`,
|
|
1538
|
+
{ "/count": [count], "/note": [note] },
|
|
1539
|
+
),
|
|
1540
|
+
app,
|
|
1541
|
+
)) as unknown as RouteBuilt;
|
|
1542
|
+
expect(built.failure).toBeNull();
|
|
1543
|
+
expect(built.constantsByEntry).toEqual({
|
|
1544
|
+
[count]: [],
|
|
1545
|
+
[note]: [],
|
|
1546
|
+
[org]: [`apps/${app}/lib/cnst.ts`, `libs/${upper}/lib/cnst.ts`, `libs/${base}/lib/cnst.ts`],
|
|
1547
|
+
});
|
|
1548
|
+
}, 240_000);
|
|
1549
|
+
|
|
1550
|
+
test("loads every store in a page reaching, through a file outside `apps/` and `libs/` or one holding a macro import, a file a store imports whose code names another model's store, and only that store where a store imports the outside file too", async () => {
|
|
1551
|
+
const [app, base, upper] = ["marina", "buoy", "keel"];
|
|
1552
|
+
const temp = await writeHarborWorkspace(app, base, upper, {
|
|
1553
|
+
"lib/_bell/bell.dictionary.ts": emptyServiceDictionary,
|
|
1554
|
+
"lib/_bell/bell.store.ts": `import { store } from "akanjs/store";\n\nimport { latch } from "../../../../shared/latch";\n\nexport class BellStore extends store("bell" as const, () => ({ bellCount: 0 })) {\n strike() {\n latch();\n this.set({ bellCount: 1 });\n }\n}\n`,
|
|
1555
|
+
"ui/chime.ts": `import { st } from "../lib/st";\nexport const chime = () => st.do.applyNotice({ noticeText: "ring" });\n`,
|
|
1556
|
+
"ui/seal.ts": `export const seal = () => "stamp";\n`,
|
|
1557
|
+
"ui/host.ts": `import { seal } from "./seal" with { type: "macro" };\nimport { chime } from "./chime";\nexport const host = [seal(), chime];\n`,
|
|
1558
|
+
"ui/Stamp.tsx": `import { host } from "./host";\nexport const Stamp = () => host;\n`,
|
|
1559
|
+
"ui/Gate.tsx": `import { gate } from "../../../shared/gate";\nexport const Gate = () => gate;\n`,
|
|
1560
|
+
"ui/Ring.tsx": `import { chime } from "./chime";\nexport const Ring = () => chime;\n`,
|
|
1561
|
+
"ui/Latch.tsx": `import { latch } from "../../../shared/latch";\nexport const Latch = () => latch;\n`,
|
|
1562
|
+
"ui/Bell.tsx": `import { st } from "../lib/st";\nexport const Bell = () => st.use.bellCount();\n`,
|
|
1563
|
+
});
|
|
1564
|
+
await writeText(
|
|
1565
|
+
path.join(temp.root, "shared/gate.ts"),
|
|
1566
|
+
`import { chime } from "../apps/${app}/ui/chime";\nexport const gate = chime;\n`,
|
|
1567
|
+
);
|
|
1568
|
+
await writeText(
|
|
1569
|
+
path.join(temp.root, "shared/latch.ts"),
|
|
1570
|
+
`import { chime } from "../apps/${app}/ui/chime";\nexport const latch = chime;\n`,
|
|
1571
|
+
);
|
|
1572
|
+
const entries = ["Note", "Ring", "Stamp", "Gate", "Latch", "Bell"].map((name) => `apps/${app}/ui/${name}.tsx`);
|
|
1573
|
+
const [note, ring, stamp, gate, latch, bell] = entries;
|
|
1574
|
+
const built = (await evaluate(
|
|
1575
|
+
temp.root,
|
|
1576
|
+
routeBuildScript(temp.root, app, entries, `apps/${app}/ui/chime.ts`, `apps/${app}/lib/__client/item.fetch.ts`),
|
|
1577
|
+
app,
|
|
1578
|
+
)) as unknown as RouteBuilt;
|
|
1579
|
+
const noticeStoreFile = `libs/${base}/lib/_notice/notice.store.ts`;
|
|
1580
|
+
const unnamedStoreFile = `libs/${upper}/lib/_crew/crew.store.ts`;
|
|
1581
|
+
expect(built.failure).toBeNull();
|
|
1582
|
+
expect(built.storeFilesByEntry).toEqual({
|
|
1583
|
+
[note]: [],
|
|
1584
|
+
[ring]: [noticeStoreFile],
|
|
1585
|
+
[stamp]: expect.arrayContaining([noticeStoreFile, unnamedStoreFile]),
|
|
1586
|
+
[gate]: expect.arrayContaining([noticeStoreFile, unnamedStoreFile]),
|
|
1587
|
+
[latch]: [noticeStoreFile],
|
|
1588
|
+
[bell]: [`apps/${app}/lib/_bell/bell.store.ts`, noticeStoreFile],
|
|
1589
|
+
});
|
|
1590
|
+
}, 240_000);
|
|
1591
|
+
});
|