@akanjs/devkit 3.3.0-rc.3 → 3.3.0-rc.30
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,737 @@
|
|
|
1
|
+
import { beforeAll, describe, expect, test } from "bun:test";
|
|
2
|
+
import { FetchClient } from "akanjs/fetch";
|
|
3
|
+
import type { RuntimeNameTable } from "./runtimeNameTable";
|
|
4
|
+
import { runtimeFixtureTables, runtimeUploadTable } from "./runtimeTable.fixture";
|
|
5
|
+
import { RuntimeUse, type RuntimeUseOptions, type RuntimeUseVerdict } from "./runtimeUse";
|
|
6
|
+
|
|
7
|
+
let demo: RuntimeNameTable;
|
|
8
|
+
let kit: RuntimeNameTable;
|
|
9
|
+
let fk: RuntimeNameTable;
|
|
10
|
+
|
|
11
|
+
beforeAll(async () => {
|
|
12
|
+
({ demo, kit } = await runtimeFixtureTables());
|
|
13
|
+
fk = await runtimeUploadTable();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const ownTableOf = (fileName: string) =>
|
|
17
|
+
fileName.startsWith("apps/demo/") ? demo : fileName.startsWith("libs/kit/") ? kit : null;
|
|
18
|
+
|
|
19
|
+
const appImport = 'import { fetch, sig, st } from "@apps/demo/client";\n';
|
|
20
|
+
|
|
21
|
+
const summaryOf = (verdict: RuntimeUseVerdict) =>
|
|
22
|
+
verdict.resolvable
|
|
23
|
+
? [
|
|
24
|
+
...verdict.owners.map(({ scope, module, needs }) => `${scope}/${module} ${needs}`),
|
|
25
|
+
...(verdict.baseStore ? ["base store"] : []),
|
|
26
|
+
...(verdict.baseDescriptor ? ["base descriptor"] : []),
|
|
27
|
+
]
|
|
28
|
+
: `${verdict.reason}: ${verdict.text}`;
|
|
29
|
+
|
|
30
|
+
const analyze = (
|
|
31
|
+
text: string,
|
|
32
|
+
fileName = "apps/demo/ui/Card.tsx",
|
|
33
|
+
options?: RuntimeUseOptions,
|
|
34
|
+
consumer = ownTableOf(fileName),
|
|
35
|
+
) => summaryOf(RuntimeUse.analyze({ fileName, text }, consumer, options));
|
|
36
|
+
|
|
37
|
+
interface UseCase {
|
|
38
|
+
shape: string;
|
|
39
|
+
text: string;
|
|
40
|
+
file?: string;
|
|
41
|
+
expected: string[] | string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const cases: [UseCase, UseCase][] = [
|
|
45
|
+
[
|
|
46
|
+
{
|
|
47
|
+
shape: "a read by a written-out name",
|
|
48
|
+
text: `${appImport}export const Card = () => {
|
|
49
|
+
st.do["clearDraft"]();
|
|
50
|
+
return st.use.draft();
|
|
51
|
+
};
|
|
52
|
+
`,
|
|
53
|
+
expected: ["apps/demo/memo store"],
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
shape: "a read by a name picked at run time",
|
|
57
|
+
text: `${appImport}export const run = (name: string) => st.do[name]();\n`,
|
|
58
|
+
expected: "computed-access: st.do[name]",
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
[
|
|
62
|
+
{
|
|
63
|
+
shape: "destructuring that names each member, nested or renamed",
|
|
64
|
+
text: `${appImport}const { clearDraft, setPinned: pin } = st.do;
|
|
65
|
+
const { use: { label } } = st;
|
|
66
|
+
export const reset = () => [clearDraft(), pin(false), label()];
|
|
67
|
+
`,
|
|
68
|
+
expected: ["apps/demo/memo store", "apps/demo/note store", "libs/kit/util store"],
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
shape: "destructuring with a rest element",
|
|
72
|
+
text: `${appImport}const { clearDraft, ...rest } = st.do;\nexport const reset = () => [clearDraft(), rest];\n`,
|
|
73
|
+
expected: "hidden-by-destructuring: ...rest",
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
[
|
|
77
|
+
{
|
|
78
|
+
shape: "a cast of a value read by name",
|
|
79
|
+
text: `${appImport}export const draftOf = () => st.use.draft() as string;\n`,
|
|
80
|
+
expected: ["apps/demo/memo store"],
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
shape: "a cast of the runtime object handed on",
|
|
84
|
+
text: `${appImport}export const actions = () => st.do as unknown as Record<string, () => void>;\n`,
|
|
85
|
+
expected: "passed-on: st.do as unknown as Record<string, () => void>",
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
[
|
|
89
|
+
{
|
|
90
|
+
shape: "a handler that reads by name",
|
|
91
|
+
text: `${appImport}export const Save = () => <button onClick={() => st.do.clearDraft()} />;\n`,
|
|
92
|
+
expected: ["apps/demo/memo store"],
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
shape: "the runtime object handed to a component",
|
|
96
|
+
text: `${appImport}export const Save = () => <Panel fetch={fetch} />;\n`,
|
|
97
|
+
expected: "passed-on: fetch",
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
[
|
|
101
|
+
{
|
|
102
|
+
shape: "a re-export of a name that is not the runtime",
|
|
103
|
+
text: 'export { usePage } from "@apps/demo/client";\n',
|
|
104
|
+
expected: [],
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
shape: "a re-export of the runtime object",
|
|
108
|
+
text: 'export { sig } from "@apps/demo/client";\n',
|
|
109
|
+
expected: "re-exported: sig",
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
[
|
|
113
|
+
{
|
|
114
|
+
shape: "a local alias kept in the file",
|
|
115
|
+
text: `${appImport}const actions = st.do;\nexport const reset = () => actions.clearDraft();\n`,
|
|
116
|
+
expected: ["apps/demo/memo store"],
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
shape: "a local alias exported",
|
|
120
|
+
text: `${appImport}export const actions = st.do;\n`,
|
|
121
|
+
expected: "re-exported: actions = st.do",
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
[
|
|
125
|
+
{
|
|
126
|
+
shape: "a name the runtime answers",
|
|
127
|
+
text: `${appImport}export const reset = () => st.do.clearDraft();\n`,
|
|
128
|
+
expected: ["apps/demo/memo store"],
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
shape: "a name the runtime does not answer",
|
|
132
|
+
text: `${appImport}export const reset = () => st.do.clearEverything();\n`,
|
|
133
|
+
expected: "unknown-name: st.do.clearEverything",
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
[
|
|
137
|
+
{
|
|
138
|
+
shape: "the store's own methods",
|
|
139
|
+
text: `${appImport}export const reset = () => st.set({ draft: st.get().label });\n`,
|
|
140
|
+
expected: ["apps/demo/memo store", "libs/kit/util store"],
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
shape: "a store member that is not a method or a runtime object",
|
|
144
|
+
text: `${appImport}export const reset = () => st.reset();\n`,
|
|
145
|
+
expected: "unknown-name: st.reset",
|
|
146
|
+
},
|
|
147
|
+
],
|
|
148
|
+
[
|
|
149
|
+
{
|
|
150
|
+
shape: "a named import from the runtime",
|
|
151
|
+
text: `${appImport}export const reset = () => st.do.clearDraft();\n`,
|
|
152
|
+
expected: ["apps/demo/memo store"],
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
shape: "the runtime import that reaches past module names",
|
|
156
|
+
text: 'import { runtime } from "@apps/demo/client";\nexport const reset = () => runtime.st;\n',
|
|
157
|
+
expected: "unknown-name: runtime",
|
|
158
|
+
},
|
|
159
|
+
],
|
|
160
|
+
[
|
|
161
|
+
{
|
|
162
|
+
shape: "a type-only import of the root store",
|
|
163
|
+
text: 'import type { RootStore } from "@apps/demo/client";\nexport let root: RootStore | null = null;\n',
|
|
164
|
+
expected: [],
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
shape: "the store barrel read as a value",
|
|
168
|
+
text: 'import { store } from "@apps/demo/client";\nexport const memoStore = () => store.memo;\n',
|
|
169
|
+
expected: "whole-runtime-import: store",
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
[
|
|
173
|
+
{
|
|
174
|
+
shape: "a named import of the client barrel",
|
|
175
|
+
text: `${appImport}export const reset = () => st.do.clearDraft();\n`,
|
|
176
|
+
expected: ["apps/demo/memo store"],
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
shape: "a namespace import of the client barrel",
|
|
180
|
+
text: 'import * as client from "@apps/demo/client";\nexport const reset = () => client.st.do.clearDraft();\n',
|
|
181
|
+
expected: "whole-runtime-import: client",
|
|
182
|
+
},
|
|
183
|
+
],
|
|
184
|
+
[
|
|
185
|
+
{
|
|
186
|
+
shape: "a static import of the client barrel",
|
|
187
|
+
text: `${appImport}export const reset = () => st.do.clearDraft();\n`,
|
|
188
|
+
expected: ["apps/demo/memo store"],
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
shape: "a dynamic import of the client barrel",
|
|
192
|
+
text: 'export const load = () => import("@apps/demo/client");\n',
|
|
193
|
+
expected: 'whole-runtime-import: import("@apps/demo/client")',
|
|
194
|
+
},
|
|
195
|
+
],
|
|
196
|
+
[
|
|
197
|
+
{
|
|
198
|
+
shape: "a write whose keys are written out, through branches, spreads and an updater",
|
|
199
|
+
text: `${appImport}export const save = (pin: boolean) => {
|
|
200
|
+
st.set({ draft: "", ...(pin ? { pinned: true } : {}) });
|
|
201
|
+
st.set((state) => ({ draft: state.draft.trim() }));
|
|
202
|
+
};
|
|
203
|
+
`,
|
|
204
|
+
expected: ["apps/demo/memo store", "apps/demo/note store"],
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
shape: "a write of an object built elsewhere",
|
|
208
|
+
text: `${appImport}export const save = (patch: object) => st.set(patch);\n`,
|
|
209
|
+
expected: "computed-access: patch",
|
|
210
|
+
},
|
|
211
|
+
],
|
|
212
|
+
[
|
|
213
|
+
{
|
|
214
|
+
shape: "a selector written inline",
|
|
215
|
+
text: `${appImport}export const Draft = () => {
|
|
216
|
+
const draft = st.sel((state) => state.draft);
|
|
217
|
+
st.sub((state) => state.pinned, (pinned) => pinned);
|
|
218
|
+
return draft;
|
|
219
|
+
};
|
|
220
|
+
`,
|
|
221
|
+
expected: ["apps/demo/memo store", "apps/demo/note store"],
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
shape: "a selector defined elsewhere",
|
|
225
|
+
text: `${appImport}const pick = (state: { draft: string }) => state.draft;\nexport const Draft = () => st.sel(pick);\n`,
|
|
226
|
+
expected: "passed-on: pick",
|
|
227
|
+
},
|
|
228
|
+
],
|
|
229
|
+
[
|
|
230
|
+
{
|
|
231
|
+
shape: "a cast to the root store, read by name",
|
|
232
|
+
file: "apps/demo/lib/memo/memoDraft.ts",
|
|
233
|
+
text: `import type { RootStore } from "../st";
|
|
234
|
+
|
|
235
|
+
export const resetDraft = (self: unknown) => {
|
|
236
|
+
const root = self as RootStore;
|
|
237
|
+
root.clearDraft();
|
|
238
|
+
return root.get().pinned;
|
|
239
|
+
};
|
|
240
|
+
`,
|
|
241
|
+
expected: ["apps/demo/memo store", "apps/demo/note store"],
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
shape: "the root store used as a value",
|
|
245
|
+
file: "apps/demo/lib/memo/memoDraft.ts",
|
|
246
|
+
text: 'import { RootStore } from "../st";\n\nexport const make = () => new RootStore();\n',
|
|
247
|
+
expected: "whole-runtime-import: RootStore",
|
|
248
|
+
},
|
|
249
|
+
],
|
|
250
|
+
[
|
|
251
|
+
{
|
|
252
|
+
shape: "a const alias read in a function declared above it",
|
|
253
|
+
text: `${appImport}export const save = () => actions.clearDraft();\nconst actions = st.do;\n`,
|
|
254
|
+
expected: ["apps/demo/memo store"],
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
shape: "a reassignable alias",
|
|
258
|
+
text: `${appImport}let actions = st.do;\nexport const save = () => actions.clearDraft();\n`,
|
|
259
|
+
expected: "passed-on: actions = st.do",
|
|
260
|
+
},
|
|
261
|
+
],
|
|
262
|
+
[
|
|
263
|
+
{
|
|
264
|
+
shape: "a parameter that shadows the runtime name",
|
|
265
|
+
text: `${appImport}export const run = (st: Record<string, () => void>, name: string) => st[name]?.();\n`,
|
|
266
|
+
expected: [],
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
shape: "the runtime name itself read by a computed key",
|
|
270
|
+
text: `${appImport}export const run = (name: "do" | "use") => st[name];\n`,
|
|
271
|
+
expected: "computed-access: st[name]",
|
|
272
|
+
},
|
|
273
|
+
],
|
|
274
|
+
];
|
|
275
|
+
|
|
276
|
+
describe("RuntimeUse.analyze", () => {
|
|
277
|
+
for (const [resolvable, whole] of cases)
|
|
278
|
+
test(`resolves ${resolvable.shape}, and loads the whole runtime for ${whole.shape}`, () => {
|
|
279
|
+
expect(analyze(resolvable.text, resolvable.file)).toEqual(resolvable.expected);
|
|
280
|
+
expect(analyze(whole.text, whole.file)).toEqual(whole.expected);
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
test("owns a slice, a signal handle and a store name by the store module, a lib name by the lib", () => {
|
|
284
|
+
expect(
|
|
285
|
+
analyze(
|
|
286
|
+
`${appImport}export const load = () => [fetch.slice.memoInBoard, sig.note.refName, fetch.memoNote(), st.do.pickLabel("x")];\n`,
|
|
287
|
+
),
|
|
288
|
+
).toEqual(["apps/demo/memo store", "apps/demo/note store", "libs/kit/util store"]);
|
|
289
|
+
expect(analyze(`${appImport}export const count = () => [fetch.memoNote(), st.use.memo()];\n`)).toEqual([
|
|
290
|
+
"apps/demo/memo store",
|
|
291
|
+
]);
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
test("answers a name of the scope that loads the file, the framework's own names with no owner", () => {
|
|
295
|
+
const count = "export const count = () => st.use.noteCount();\n";
|
|
296
|
+
expect(analyze(`${appImport}${count}`)).toEqual(["apps/demo/note store"]);
|
|
297
|
+
expect(analyze(`import { st } from "@libs/kit/client";\n${count}`, "libs/kit/ui/Count.tsx")).toEqual([
|
|
298
|
+
"libs/kit/note store",
|
|
299
|
+
]);
|
|
300
|
+
expect(analyze(`import { st } from "akanjs/store";\n${count}`)).toEqual(["apps/demo/note store"]);
|
|
301
|
+
expect(analyze(`${appImport}export const go = () => st.do.setPath("/");\n`)).toEqual(["base store"]);
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
test("tells the framework's own store keys, which every page has, from its own descriptors", () => {
|
|
305
|
+
expect(analyze(`${appImport}export const a = () => st.use.theme();\n`)).toEqual(["base store"]);
|
|
306
|
+
expect(analyze(`${appImport}export const a = () => fetch.ping();\n`)).toEqual(["base descriptor"]);
|
|
307
|
+
expect(analyze(`${appImport}export const a = () => [st.do.setTheme("dark"), fetch.ping()];\n`)).toEqual([
|
|
308
|
+
"base store",
|
|
309
|
+
"base descriptor",
|
|
310
|
+
]);
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
test("needs a module's store for every fetch value that framework UI drives the store with", () => {
|
|
314
|
+
const remove =
|
|
315
|
+
'"use client";\nimport { fetch } from "@apps/demo/client";\nimport { Model } from "akanjs/ui";\nexport const Remove = ({ memoId }: { memoId: string }) => <Model.Remove modelId={memoId} slice={fetch.slice.memoInBoard}>x</Model.Remove>;\n';
|
|
316
|
+
expect(analyze(remove)).toEqual(["apps/demo/memo store"]);
|
|
317
|
+
expect(
|
|
318
|
+
[
|
|
319
|
+
"fetch.slice.memoInBoard",
|
|
320
|
+
"fetch.initMemoInBoard()",
|
|
321
|
+
"fetch.getMemoInitInBoard()",
|
|
322
|
+
"fetch.memoListInBoard()",
|
|
323
|
+
"fetch.memoInsightInBoard()",
|
|
324
|
+
"fetch.subscribeMemoLiveInBoard(() => undefined)",
|
|
325
|
+
"fetch.viewMemo(id)",
|
|
326
|
+
"fetch.getMemoView(id)",
|
|
327
|
+
"fetch.editMemo(id)",
|
|
328
|
+
"fetch.getMemoEdit(id)",
|
|
329
|
+
"fetch.serializedSignal.memo",
|
|
330
|
+
"sig.memo.refName",
|
|
331
|
+
"sig.memo.fetch.memoNote()",
|
|
332
|
+
].map((use) => analyze(`${appImport}export const a = (id: string) => ${use};\n`)),
|
|
333
|
+
).toEqual(Array(13).fill(["apps/demo/memo store"]));
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
test("needs only a module's descriptor for a plain endpoint, a generated read or write, and a socket", () => {
|
|
337
|
+
expect(
|
|
338
|
+
[
|
|
339
|
+
"fetch.memoNote()",
|
|
340
|
+
"fetch.memoTyping(true)",
|
|
341
|
+
"fetch.listenMemoTyping(() => undefined)",
|
|
342
|
+
"fetch.memo(id)",
|
|
343
|
+
"fetch.lightMemo(id)",
|
|
344
|
+
"fetch.createMemo({})",
|
|
345
|
+
"fetch.updateMemo(id, {})",
|
|
346
|
+
"fetch.mergeMemo(id, {})",
|
|
347
|
+
].map((use) => analyze(`${appImport}export const a = (id: string) => ${use};\n`)),
|
|
348
|
+
).toEqual(Array(8).fill(["apps/demo/memo descriptor"]));
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
test("reads the fetch client's own members as no module's name, and the ones a name is picked through as the whole runtime", () => {
|
|
352
|
+
const own = [
|
|
353
|
+
"ws",
|
|
354
|
+
"http",
|
|
355
|
+
"origin",
|
|
356
|
+
"jwt",
|
|
357
|
+
"logger",
|
|
358
|
+
"setJwt",
|
|
359
|
+
"setTimeout",
|
|
360
|
+
"connect",
|
|
361
|
+
"connectOnUse",
|
|
362
|
+
"disconnect",
|
|
363
|
+
];
|
|
364
|
+
expect(own.map((member) => analyze(`${appImport}export const a = fetch.${member};\n`))).toEqual(
|
|
365
|
+
Array(own.length).fill([]),
|
|
366
|
+
);
|
|
367
|
+
expect(analyze(`${appImport}export const a = () => fetch.configureWs({});\n`)).toEqual([]);
|
|
368
|
+
expect(analyze(`${appImport}export const a = () => [fetch.ws, fetch.memoNote()];\n`)).toEqual([
|
|
369
|
+
"apps/demo/memo descriptor",
|
|
370
|
+
]);
|
|
371
|
+
for (const member of ["handler", "instance", "clone"])
|
|
372
|
+
expect(analyze(`${appImport}export const a = fetch.${member};\n`)).toBeString();
|
|
373
|
+
const methods = Object.getOwnPropertyNames(FetchClient.prototype).filter((name) => name !== "constructor");
|
|
374
|
+
const picking = ["ownSerializedSignal", "applySignal", "clone"];
|
|
375
|
+
expect(methods.filter((name) => !picking.includes(name) && !own.includes(name))).toEqual(["configureWs"]);
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
test("needs the file-upload module's descriptor for an upload, which reads it as it runs", () => {
|
|
379
|
+
expect(
|
|
380
|
+
analyze(
|
|
381
|
+
'import { fetch, st } from "@libs/fk/client";\nexport const up = (files: File[]) => [st.do.uploadImageOnUser(files), fetch.addUserFiles(files)];\n',
|
|
382
|
+
"libs/fk/ui/Upload.tsx",
|
|
383
|
+
undefined,
|
|
384
|
+
fk,
|
|
385
|
+
),
|
|
386
|
+
).toEqual(["libs/fk/file descriptor", "libs/fk/user store"]);
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
test("loads the whole runtime when a spread argument hides which argument lands where", () => {
|
|
390
|
+
expect(
|
|
391
|
+
[
|
|
392
|
+
"st.sub((s, prev) => prev.memoForm.content.length, ...([] as []))",
|
|
393
|
+
"st.sel(...([(s: { draft: string }) => s.draft] as const))",
|
|
394
|
+
"st.ref(...([(s: { draft: string }) => s.draft] as const))",
|
|
395
|
+
"st.set(...([{ draft: '' }] as const))",
|
|
396
|
+
].map((use) => analyze(`${appImport}export const a = () => ${use};\n`).slice(0, 15)),
|
|
397
|
+
).toEqual(Array(4).fill("computed-access"));
|
|
398
|
+
expect(
|
|
399
|
+
analyze(
|
|
400
|
+
'import { store } from "akanjs/store";\n\nexport class MemoStore extends store("memo" as const, () => ({ draft: "" })) {\n read() {\n return this.pick(...(["draft"] as const));\n }\n}\n',
|
|
401
|
+
"apps/demo/lib/memo/memo.store.ts",
|
|
402
|
+
).slice(0, 15),
|
|
403
|
+
).toBe("computed-access");
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
test("leaves the global fetch, an agentic member and a file with no runtime import alone", () => {
|
|
407
|
+
expect(analyze(`${appImport}export const ping = () => globalThis.fetch("/ping").then(() => st.tool);\n`)).toEqual(
|
|
408
|
+
[],
|
|
409
|
+
);
|
|
410
|
+
expect(analyze('export const ping = () => fetch("/ping");\n')).toEqual([]);
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
test("loads the whole runtime of a scope with no generated runtime, and for a bare import of one", () => {
|
|
414
|
+
expect(
|
|
415
|
+
analyze(
|
|
416
|
+
'import { st } from "@apps/other/client";\nexport const reset = () => st.do.clearDraft();\n',
|
|
417
|
+
"apps/other/ui/X.tsx",
|
|
418
|
+
),
|
|
419
|
+
).toBe('whole-runtime-import: "@apps/other/client"');
|
|
420
|
+
expect(analyze('import "@apps/demo/client";\n')).toBe('whole-runtime-import: import "@apps/demo/client";');
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
test("resolves a specifier the caller maps to a runtime, and reports every problem in source order", () => {
|
|
424
|
+
const runtimeOf = (specifier: string) =>
|
|
425
|
+
specifier === "~/client" ? { scope: "apps/demo", kind: "client" as const } : null;
|
|
426
|
+
expect(
|
|
427
|
+
analyze('import { st } from "~/client";\nexport const reset = () => st.do.clearDraft();\n', undefined, {
|
|
428
|
+
runtimeOf,
|
|
429
|
+
}),
|
|
430
|
+
).toEqual(["apps/demo/memo store"]);
|
|
431
|
+
const verdict = RuntimeUse.analyze(
|
|
432
|
+
{
|
|
433
|
+
fileName: "apps/demo/ui/Card.tsx",
|
|
434
|
+
text: `${appImport}export const a = (k: string) => st.do[k];\nexport const b = () => <Panel sig={sig} />;\n`,
|
|
435
|
+
},
|
|
436
|
+
demo,
|
|
437
|
+
);
|
|
438
|
+
expect(
|
|
439
|
+
verdict.resolvable ? [] : verdict.problems.map(({ reason, line, column }) => `${reason} ${line}:${column}`),
|
|
440
|
+
).toEqual(["computed-access 2:33", "passed-on 3:36"]);
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
test("follows the framework's own fetch and sig as it follows the scope's", () => {
|
|
444
|
+
expect(
|
|
445
|
+
analyze(
|
|
446
|
+
'import { st } from "@apps/demo/client";\nimport { fetch as f } from "akanjs/client";\nexport const x = () => [st.use.draft(), f.noteCount()];\n',
|
|
447
|
+
),
|
|
448
|
+
).toEqual(["apps/demo/memo store", "apps/demo/note descriptor"]);
|
|
449
|
+
expect(analyze('import { sig as s } from "akanjs/client";\nexport const ref = () => s.memo.refName;\n')).toEqual([
|
|
450
|
+
"apps/demo/memo store",
|
|
451
|
+
]);
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
test("follows a store's `this` as itself through any cast, and as every store through the cast to its RootStore", () => {
|
|
455
|
+
const file = "apps/demo/lib/memo/memo.store.ts";
|
|
456
|
+
const storeOf = (body: string, head = 'import type { RootStore } from "../st";\n') =>
|
|
457
|
+
analyze(
|
|
458
|
+
`import { store } from "akanjs/store";\n${head}import { sig } from "../useClient";\n\nexport class MemoStore extends store(sig.memo, () => ({ draft: "" })) {\n${body}\n}\n`,
|
|
459
|
+
file,
|
|
460
|
+
);
|
|
461
|
+
expect(
|
|
462
|
+
storeOf(
|
|
463
|
+
" clearDraft() {\n this.set({ draft: '' });\n (this as unknown as RootStore).setPinned(true);\n }",
|
|
464
|
+
),
|
|
465
|
+
).toEqual(["apps/demo/memo store", "apps/demo/note store"]);
|
|
466
|
+
const memoOnly = ["apps/demo/memo store"];
|
|
467
|
+
const mergeOf = (write: string, head?: string) =>
|
|
468
|
+
storeOf(
|
|
469
|
+
` #recount = (state: { draft: string; pinned: boolean }) => {\n state.draft = String(state.pinned);\n };\n merge(patch: { draft: string }, ready: boolean) {\n ${write};\n }`,
|
|
470
|
+
head,
|
|
471
|
+
);
|
|
472
|
+
expect(
|
|
473
|
+
[
|
|
474
|
+
"this.set({ ...patch })",
|
|
475
|
+
"this.set({ ...(ready ? patch : { draft: '' }) })",
|
|
476
|
+
"this.set({ ...patch, draft: '' })",
|
|
477
|
+
].map((write) => mergeOf(write)),
|
|
478
|
+
).toEqual([memoOnly, memoOnly, memoOnly]);
|
|
479
|
+
expect(mergeOf("this.set((state) => {\n state.draft = String(state.pinned);\n })")).toEqual([
|
|
480
|
+
"apps/demo/memo store",
|
|
481
|
+
"apps/demo/note store",
|
|
482
|
+
]);
|
|
483
|
+
const recount =
|
|
484
|
+
'import type { RootStore } from "../st";\nconst recount = (state: { draft: string; pinned: boolean }) => {\n state.draft = String(state.pinned);\n};\nconst build = () => recount;\n';
|
|
485
|
+
expect(
|
|
486
|
+
[
|
|
487
|
+
"this.set(patch)",
|
|
488
|
+
"this.set(recount)",
|
|
489
|
+
"this.set(this.#recount)",
|
|
490
|
+
"this.set(build())",
|
|
491
|
+
"this.set(ready ? { draft: '' } : patch)",
|
|
492
|
+
"this.set(ready && recount)",
|
|
493
|
+
"this.set(() => patch)",
|
|
494
|
+
].map((write) => mergeOf(write, recount)),
|
|
495
|
+
).toEqual([
|
|
496
|
+
"computed-access: patch",
|
|
497
|
+
"computed-access: recount",
|
|
498
|
+
"computed-access: this.#recount",
|
|
499
|
+
"computed-access: build()",
|
|
500
|
+
"computed-access: patch",
|
|
501
|
+
"computed-access: recount",
|
|
502
|
+
"computed-access: patch",
|
|
503
|
+
]);
|
|
504
|
+
expect(
|
|
505
|
+
[
|
|
506
|
+
"(this as unknown as RootStore).set({ ...patch })",
|
|
507
|
+
"(this as unknown as RootStore).set(patch)",
|
|
508
|
+
"this.set({ [key]: '' })",
|
|
509
|
+
].map((write) => storeOf(` merge(patch: { draft: string }, key: string) {\n ${write};\n }`)),
|
|
510
|
+
).toEqual([expect.any(String), expect.any(String), expect.any(String)]);
|
|
511
|
+
expect(analyze(`${appImport}export const a = (patch: object) => st.set({ ...patch });\n`)).toBeString();
|
|
512
|
+
expect(storeOf(" pin() {\n this.setPinned(true);\n }")).toEqual([
|
|
513
|
+
"apps/demo/memo store",
|
|
514
|
+
"apps/demo/note store",
|
|
515
|
+
]);
|
|
516
|
+
expect([
|
|
517
|
+
storeOf(" pin() {\n (this as any).setPinned(true);\n }"),
|
|
518
|
+
storeOf(
|
|
519
|
+
" pin() {\n (this as unknown as Root).setPinned(true);\n }",
|
|
520
|
+
'import type { RootStore } from "../st";\ntype Root = RootStore;\n',
|
|
521
|
+
),
|
|
522
|
+
storeOf(" pin() {\n (this as unknown as RootStore & {}).setPinned(true);\n }"),
|
|
523
|
+
storeOf(
|
|
524
|
+
" pin() {\n (this as unknown as RootStore).setPinned(true);\n }",
|
|
525
|
+
'import type { RootStore } from "akanjs/store";\n',
|
|
526
|
+
),
|
|
527
|
+
storeOf(
|
|
528
|
+
" pin() {\n (this as unknown as RootStore).setPinned(true);\n }",
|
|
529
|
+
'import type { RootStore } from "./root";\n',
|
|
530
|
+
),
|
|
531
|
+
storeOf(" pin() {\n pin(this);\n }"),
|
|
532
|
+
storeOf(" pin() {\n return (this.get() as any).pinned;\n }"),
|
|
533
|
+
storeOf(" static pin() {\n return this.name;\n }"),
|
|
534
|
+
storeOf(" pin() {\n return this.pinEverything();\n }"),
|
|
535
|
+
]).toEqual([
|
|
536
|
+
...Array.from({ length: 5 }, () => ["apps/demo/memo store", "apps/demo/note store"]),
|
|
537
|
+
"passed-on: this",
|
|
538
|
+
["apps/demo/memo store", "apps/demo/note store"],
|
|
539
|
+
"unknown-name: this",
|
|
540
|
+
"unknown-name: this.pinEverything",
|
|
541
|
+
]);
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
test("reads a runtime import written with an extension, an index or a specifier the caller maps", () => {
|
|
545
|
+
expect(analyze('import { st } from "@apps/demo/client.js";\nexport const r = () => st.do.clearDraft();\n')).toEqual(
|
|
546
|
+
["apps/demo/memo store"],
|
|
547
|
+
);
|
|
548
|
+
expect(
|
|
549
|
+
analyze(
|
|
550
|
+
'import { fetch } from "../useClient.js";\nexport const r = () => fetch.memoNote();\n',
|
|
551
|
+
"apps/demo/lib/memo/memoNote.ts",
|
|
552
|
+
),
|
|
553
|
+
).toEqual(["apps/demo/memo descriptor"]);
|
|
554
|
+
const runtimeOf = (specifier: string) =>
|
|
555
|
+
specifier === "#app" ? { scope: "apps/demo", kind: "client" as const } : null;
|
|
556
|
+
expect(
|
|
557
|
+
analyze('import { st } from "#app";\nexport const r = () => st.do.clearDraft();\n', undefined, { runtimeOf }),
|
|
558
|
+
).toEqual(["apps/demo/memo store"]);
|
|
559
|
+
});
|
|
560
|
+
|
|
561
|
+
test("follows an alias chain to its end, however many aliases sit below their use", () => {
|
|
562
|
+
expect(
|
|
563
|
+
analyze(`${appImport}export const run = () => {
|
|
564
|
+
const inner = () => y6.clearEverything();
|
|
565
|
+
return inner();
|
|
566
|
+
};
|
|
567
|
+
const y6 = y5;
|
|
568
|
+
const y5 = y4;
|
|
569
|
+
const y4 = y3;
|
|
570
|
+
const y3 = y2;
|
|
571
|
+
const y2 = y1;
|
|
572
|
+
const y1 = st.do;
|
|
573
|
+
`),
|
|
574
|
+
).toBe("unknown-name: y6.clearEverything");
|
|
575
|
+
});
|
|
576
|
+
|
|
577
|
+
test("loads the whole runtime for a reach it cannot follow, and follows a name a method parameter does not hide", () => {
|
|
578
|
+
expect(analyze('export const n = () => require("@apps/demo/client").fetch.noteCount();\n')).toBe(
|
|
579
|
+
'whole-runtime-import: require("@apps/demo/client")',
|
|
580
|
+
);
|
|
581
|
+
expect(
|
|
582
|
+
analyze(`${appImport}export const Pinned = () => st.sel(function () {\n return arguments[0].pinned;\n});\n`),
|
|
583
|
+
).toBe("hidden-by-destructuring: arguments");
|
|
584
|
+
expect(
|
|
585
|
+
analyze(`${appImport}export class Pins {\n [st.do.setPinned.name](st: unknown) {\n return st;\n }\n}\n`),
|
|
586
|
+
).toEqual(["apps/demo/note store"]);
|
|
587
|
+
expect(analyze('import {} from "@apps/demo/client";\n')).toBe(
|
|
588
|
+
'whole-runtime-import: import {} from "@apps/demo/client";',
|
|
589
|
+
);
|
|
590
|
+
});
|
|
591
|
+
|
|
592
|
+
test("answers a lib file's names from the scope that loads it, and refuses a runtime that scope does not load", () => {
|
|
593
|
+
const file = "libs/kit/ui/AddNote.tsx";
|
|
594
|
+
const text =
|
|
595
|
+
'import { fetch, st } from "../client";\nexport const add = () => [st.do.createNote(), fetch.tagCount()];\n';
|
|
596
|
+
expect(analyze(text, file, undefined, demo)).toEqual(["apps/demo/note store", "libs/kit/tag descriptor"]);
|
|
597
|
+
expect(analyze(text, file, undefined, kit)).toEqual(["libs/kit/note store", "libs/kit/tag descriptor"]);
|
|
598
|
+
expect(analyze('import { st } from "@apps/demo/client";\nexport const a = () => st.do.clearDraft();\n', file)).toBe(
|
|
599
|
+
'whole-runtime-import: "@apps/demo/client"',
|
|
600
|
+
);
|
|
601
|
+
expect(analyze(text, file, undefined, null)).toBe('whole-runtime-import: "../client"');
|
|
602
|
+
});
|
|
603
|
+
|
|
604
|
+
test("loads the whole runtime for every reach past a named import", () => {
|
|
605
|
+
expect(
|
|
606
|
+
[
|
|
607
|
+
'export * from "@apps/demo/client";\n',
|
|
608
|
+
'export * as client from "@apps/demo/client";\n',
|
|
609
|
+
'export { RootStore } from "@apps/demo/client";\n',
|
|
610
|
+
'import client = require("@apps/demo/client");\n',
|
|
611
|
+
"export const load = (name: string) => import(name);\n",
|
|
612
|
+
"const load = require;\nexport const n = () => load('x');\n",
|
|
613
|
+
'export const n = () => import.meta.require("@apps/demo/lib/useClient");\n',
|
|
614
|
+
'export const n = () => globalThis["require"]("@apps/demo/client");\n',
|
|
615
|
+
'export const worker = () => new Worker("@apps/demo/client");\n',
|
|
616
|
+
'import { st as root } from "akanjs/store/baseSt";\nexport const n = () => root;\n',
|
|
617
|
+
'import { StoreRegistry } from "akanjs/store";\nexport const n = () => StoreRegistry.build;\n',
|
|
618
|
+
'import * as framework from "akanjs/store";\nexport const n = () => framework.StoreRegistry;\n',
|
|
619
|
+
'import { RootStore } from "../st";\nexport const n = (self: unknown) => (self as RootStore).clearDraft();\n',
|
|
620
|
+
'import { runtime } from "@apps/demo/lib/usePage";\nexport const n = () => runtime;\n',
|
|
621
|
+
'import { memo } from "../st";\nexport const n = () => memo;\n',
|
|
622
|
+
].map((text) => analyze(text, "apps/demo/lib/memo/memoLoad.ts")),
|
|
623
|
+
).toEqual([
|
|
624
|
+
're-exported: export * from "@apps/demo/client";',
|
|
625
|
+
're-exported: export * as client from "@apps/demo/client";',
|
|
626
|
+
"re-exported: RootStore",
|
|
627
|
+
'whole-runtime-import: import client = require("@apps/demo/client");',
|
|
628
|
+
"whole-runtime-import: import(name)",
|
|
629
|
+
"whole-runtime-import: require",
|
|
630
|
+
'whole-runtime-import: import.meta.require("@apps/demo/lib/useClient")',
|
|
631
|
+
'whole-runtime-import: globalThis["require"]("@apps/demo/client")',
|
|
632
|
+
'whole-runtime-import: "@apps/demo/client"',
|
|
633
|
+
"whole-runtime-import: st as root",
|
|
634
|
+
"whole-runtime-import: StoreRegistry",
|
|
635
|
+
"whole-runtime-import: framework.StoreRegistry",
|
|
636
|
+
"whole-runtime-import: RootStore",
|
|
637
|
+
"unknown-name: runtime",
|
|
638
|
+
"whole-runtime-import: memo",
|
|
639
|
+
]);
|
|
640
|
+
});
|
|
641
|
+
|
|
642
|
+
test("follows a namespace of the framework, a signal handed to its store, and a function typed to the root store", () => {
|
|
643
|
+
const head = 'import * as framework from "akanjs/client";\nimport { store } from "akanjs/store";\n';
|
|
644
|
+
expect(
|
|
645
|
+
analyze(
|
|
646
|
+
`${head}import type { RootStore } from "../st";
|
|
647
|
+
import { sig } from "../useClient";
|
|
648
|
+
export class Draft extends store(sig.memo, () => ({ draftOf: "" })) {}
|
|
649
|
+
export function pin(this: RootStore) {
|
|
650
|
+
this.setPinned(this.pick("draft").draft === "");
|
|
651
|
+
}
|
|
652
|
+
export const n = () => [framework.fetch.memoNote(), framework.cn, sig.note.fetch.noteCount()];
|
|
653
|
+
`,
|
|
654
|
+
"apps/demo/lib/memo/memoPin.ts",
|
|
655
|
+
),
|
|
656
|
+
).toEqual(["apps/demo/memo store", "apps/demo/note store"]);
|
|
657
|
+
expect(analyze('import { sig } from "@apps/demo/client";\nexport const n = () => sig.memo.fetch;\n')).toBe(
|
|
658
|
+
"passed-on: sig.memo.fetch",
|
|
659
|
+
);
|
|
660
|
+
});
|
|
661
|
+
|
|
662
|
+
test("leaves `this` alone outside a store class, and loads the whole runtime when a store file's helper may be the store", () => {
|
|
663
|
+
expect(
|
|
664
|
+
analyze(
|
|
665
|
+
`${appImport}export class Timer {\n tick() {\n return this.anything();\n }\n}\nexport const n = () => st.do.clearDraft();\n`,
|
|
666
|
+
),
|
|
667
|
+
).toEqual(["apps/demo/memo store"]);
|
|
668
|
+
expect(
|
|
669
|
+
analyze(
|
|
670
|
+
'import { store } from "akanjs/store";\n\nfunction pinAll(this: { setPinned: (pin: boolean) => void }) {\n this.setPinned(true);\n}\n\nexport class MemoStore extends store("memo" as const, () => ({ draft: "" })) {\n pinAll = pinAll;\n}\n',
|
|
671
|
+
"apps/demo/lib/memo/memo.store.ts",
|
|
672
|
+
),
|
|
673
|
+
).toBe("passed-on: this");
|
|
674
|
+
expect(
|
|
675
|
+
analyze(
|
|
676
|
+
'import { store } from "akanjs/store";\n\nexport class MemoStore extends store("memo" as const, () => ({ draft: "" })) {\n reset() {\n super.set({ draft: "" });\n return [this.reset, this.slice.memoInBoard];\n }\n}\n',
|
|
677
|
+
"apps/demo/lib/memo/memo.store.ts",
|
|
678
|
+
),
|
|
679
|
+
).toEqual(["apps/demo/memo store"]);
|
|
680
|
+
});
|
|
681
|
+
|
|
682
|
+
test("reads the generated runtime pieces as the whole runtime and `st` from the page runtime as the scope's `st`", () => {
|
|
683
|
+
const file = "apps/demo/lib/memo/memoDraft.ts";
|
|
684
|
+
expect(
|
|
685
|
+
[
|
|
686
|
+
'import { st } from "../__client/_st";\nexport const n = () => st.do.clearDraft();\n',
|
|
687
|
+
'import { fetch } from "../__client/_useClient";\nexport const n = () => fetch.memoNote();\n',
|
|
688
|
+
'import { memo } from "../__client/memo.st";\nexport const n = () => memo;\n',
|
|
689
|
+
'import "../__client/memo.fetch";\nexport const n = () => 1;\n',
|
|
690
|
+
'import "../__client/_base.fetch";\nexport const n = () => 1;\n',
|
|
691
|
+
].map((text) => analyze(text, file)),
|
|
692
|
+
).toEqual([
|
|
693
|
+
"whole-runtime-import: st",
|
|
694
|
+
"whole-runtime-import: fetch",
|
|
695
|
+
"whole-runtime-import: memo",
|
|
696
|
+
'whole-runtime-import: import "../__client/memo.fetch";',
|
|
697
|
+
'whole-runtime-import: import "../__client/_base.fetch";',
|
|
698
|
+
]);
|
|
699
|
+
expect(
|
|
700
|
+
analyze(
|
|
701
|
+
'import type { RootStore } from "../__client/_st";\n\nexport const reset = (self: unknown) => (self as RootStore).clearDraft();\n',
|
|
702
|
+
file,
|
|
703
|
+
),
|
|
704
|
+
).toEqual(["apps/demo/memo store"]);
|
|
705
|
+
const read = "export const n = () => [st.do.clearDraft(), st.use.theme()];\n";
|
|
706
|
+
expect(analyze(`import { st } from "@apps/demo/lib/usePage";\n${read}`)).toEqual(
|
|
707
|
+
analyze(`import { st } from "@apps/demo/client";\n${read}`),
|
|
708
|
+
);
|
|
709
|
+
expect(analyze(`import { st } from "@apps/demo/lib/usePage";\n${read}`)).toEqual([
|
|
710
|
+
"apps/demo/memo store",
|
|
711
|
+
"base store",
|
|
712
|
+
]);
|
|
713
|
+
});
|
|
714
|
+
|
|
715
|
+
test("reads the scope and runtime kind of an import specifier", () => {
|
|
716
|
+
const file = "apps/demo/lib/memo/Memo.Zone.tsx";
|
|
717
|
+
expect(
|
|
718
|
+
[
|
|
719
|
+
"../useClient",
|
|
720
|
+
"../st.ts",
|
|
721
|
+
"@libs/kit/client",
|
|
722
|
+
"@apps/demo/lib/usePage",
|
|
723
|
+
"akanjs/store",
|
|
724
|
+
"akanjs/client",
|
|
725
|
+
"./client",
|
|
726
|
+
].map((specifier) => RuntimeUse.targetOf(specifier, file)),
|
|
727
|
+
).toEqual([
|
|
728
|
+
{ scope: "apps/demo", kind: "useClient" },
|
|
729
|
+
{ scope: "apps/demo", kind: "st" },
|
|
730
|
+
{ scope: "libs/kit", kind: "client" },
|
|
731
|
+
{ scope: "apps/demo", kind: "usePage" },
|
|
732
|
+
{ scope: "apps/demo", kind: "framework-store" },
|
|
733
|
+
{ scope: "apps/demo", kind: "framework-client" },
|
|
734
|
+
null,
|
|
735
|
+
]);
|
|
736
|
+
});
|
|
737
|
+
});
|