@akanjs/cli 3.1.1-rc.9 → 3.1.2-rc.0
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/.build-stamp +1 -1
- package/CodeAgent-dyc45f5w.js +11 -0
- package/{CodeAgentRpcHost-9g27hmer.js → CodeAgentRpcHost-6dzfkvsc.js} +1 -1
- package/CodeAgentRpcListener-tcwrdvst.js +182 -0
- package/{CodeTui-z5vkm9ea.js → CodeTui-q55b2zrn.js} +25 -8
- package/TunnelShare-hdq9h1hr.js +14 -0
- package/agent.command-20zaqe60.js +49 -0
- package/akanCode.js +13 -8
- package/{application.command-wthg8nn9.js → application.command-nd0fshsk.js} +45 -12
- package/{applicationBuildRunner-t2r84sz6.js → applicationBuildRunner-s13x3zqb.js} +14 -10
- package/buildBatch.proc.js +7 -7
- package/{cloud.command-sz11hpre.js → cloud.command-8kbddsz9.js} +28 -19
- package/cloud.script-hgvvajm3.js +27 -0
- package/code.command-625bg8s8.js +345 -0
- package/commandManifest.json +1 -1
- package/{context.command-15j9b7c0.js → context.command-p6haqjay.js} +20 -18
- package/context.runner-rsnqnk9j.js +27 -0
- package/{dependencyScanner-3afj2vt1.js → dependencyScanner-78sq8m4q.js} +2 -2
- package/{devTui-q7k7bakd.js → devTui-evr3b35y.js} +1 -1
- package/{fileSys-wzzrntkw.js → fileSys-zpvt5gtf.js} +1 -1
- package/{guideline.command-snh85ctf.js → guideline.command-195g0h9a.js} +4 -4
- package/guidelines/agentRule/agentRule.instruction.md +22 -8
- package/guidelines/conventions/core.md +106 -0
- package/guidelines/conventions/rules/app.md +83 -0
- package/guidelines/conventions/rules/auth.md +46 -0
- package/guidelines/conventions/rules/config.md +60 -0
- package/guidelines/conventions/rules/constant.md +24 -0
- package/guidelines/conventions/rules/gates.md +32 -0
- package/guidelines/conventions/rules/layer.md +25 -0
- package/guidelines/conventions/rules/migration.md +27 -0
- package/guidelines/conventions/rules/module.md +90 -0
- package/guidelines/conventions/rules/page.md +56 -0
- package/guidelines/conventions/rules/sensitive.md +16 -0
- package/guidelines/conventions/rules/server.md +91 -0
- package/guidelines/conventions/rules/ssr.md +47 -0
- package/guidelines/conventions/rules/style.md +43 -0
- package/guidelines/conventions/rules/test.md +34 -0
- package/guidelines/conventions/rules/ts.md +95 -0
- package/guidelines/conventions/rules/tsx.md +76 -0
- package/guidelines/mcpRule/mcpRule.instruction.md +1 -1
- package/guidelines/pageRule/pageRule.instruction.md +8 -7
- package/guidelines/queryRule/queryRule.instruction.md +4 -0
- package/guidelines/runtimeRule/runtimeRule.instruction.md +35 -25
- package/guidelines/ssrRule/ssrRule.instruction.md +11 -10
- package/guidelines/transportRule/transportRule.instruction.md +5 -4
- package/guidelines/workspaceRecipes/workspaceRecipes.instruction.md +4 -4
- package/incrementalBuilder.proc.js +7 -7
- package/{index-301pdbzz.js → index-00a7j05x.js} +7 -7
- package/{index-js6geqjn.js → index-0j1t1h2b.js} +3 -1
- package/{index-6txx6a9p.js → index-1h2jc0x3.js} +154 -88
- package/{index-55j120r8.js → index-1qsd8ft1.js} +65 -145
- package/{index-9th4gszy.js → index-2mwjshz5.js} +233 -1271
- package/index-2nxk8wgs.js +266 -0
- package/{index-j9vyj3dj.js → index-2phm56a1.js} +49 -8
- package/index-35j83zkd.js +61 -0
- package/index-4am4dvmf.js +29 -0
- package/index-75y7bcz4.js +28 -0
- package/index-7apsdr5g.js +487 -0
- package/{index-42j4a8zq.js → index-84h43kg6.js} +8 -6
- package/index-9bv479q5.js +1 -0
- package/{index-3wypz6xj.js → index-9zy8479y.js} +11 -5
- package/{index-a5dhqkdr.js → index-a1vb3x7t.js} +273 -259
- package/{index-52w0fvh8.js → index-bns3wcpc.js} +15 -0
- package/index-cjmjvg4r.js +3622 -0
- package/{index-pcwzkdqb.js → index-defp4gmb.js} +1 -1
- package/index-ewbmfarf.js +1606 -0
- package/index-fbewhg4g.js +590 -0
- package/index-fhw7yq2d.js +653 -0
- package/{index-wcej7g4z.js → index-g500c5j9.js} +271 -105
- package/{index-74tjjsnc.js → index-g841cap9.js} +33 -37
- package/{index-2azahjaw.js → index-gr9thy79.js} +5 -5
- package/{index-4pf8g7ff.js → index-h7hehkw6.js} +3 -0
- package/{index-xjf5j657.js → index-hm0tn7qv.js} +1001 -91
- package/index-j6eeh5d7.js +138 -0
- package/{index-31es1yev.js → index-j7hwy56s.js} +108 -7
- package/{index-skk9zc1x.js → index-jc2zbwra.js} +2 -2
- package/{index-905qdgqp.js → index-khk05tsf.js} +1 -1
- package/{index-5nd1wtkv.js → index-p6x5b7hr.js} +1 -1
- package/{index-tvehn2sp.js → index-qd7xn2bk.js} +1 -1
- package/{index-a58emady.js → index-qw6814m4.js} +55 -17
- package/index-raz588b3.js +445 -0
- package/{index-at7bz0xq.js → index-s4nvxpzm.js} +2 -0
- package/{index-bt438yxm.js → index-sp0qsr7a.js} +116 -13
- package/{index-xb8809yb.js → index-sveq36gh.js} +40 -43
- package/{index-hmt54t45.js → index-t1t9wq9a.js} +4 -4
- package/index-t78230d7.js +191 -0
- package/index-tenw3mah.js +225 -0
- package/{index-qfp55x1y.js → index-tgqameyb.js} +4 -4
- package/{index-espk51ah.js → index-tp56652m.js} +6 -6
- package/index-w15mg3km.js +389 -0
- package/{index-dy0jx9ay.js → index-wwe9rsrx.js} +14 -0
- package/{index-2xcc2ax5.js → index-y4kcmbt2.js} +2 -2
- package/index-yf9wc28h.js +52 -0
- package/{index-0fz95kxe.js → index-zbrwnmf1.js} +9 -7
- package/{index-40brg4px.js → index-zttm13c3.js} +5 -5
- package/index.js +24 -23
- package/{library.command-gycrwhf1.js → library.command-63hgt9te.js} +4 -4
- package/{localRegistry.command-jtd8gaes.js → localRegistry.command-g3f8k25t.js} +46 -22
- package/{module.command-v6hgs1bc.js → module.command-r4sa2khp.js} +7 -6
- package/{package.command-shzpcfph.js → package.command-96eheyvd.js} +5 -5
- package/package.json +2 -2
- package/{page.command-ptxn5kqk.js → page.command-gs6d841d.js} +4 -4
- package/{pipeline.command-zz31pgax.js → pipeline.command-wdfvdbfj.js} +3 -3
- package/{primitive.command-a1vse91z.js → primitive.command-dfsv4mpe.js} +8 -7
- package/{projectTypecheck-2ztky9cf.js → projectTypecheck-kqj1t6hb.js} +1 -1
- package/{prompter-76k56b37.js → prompter-qrwx1p17.js} +2 -2
- package/quality.command-webzxee2.js +78 -0
- package/{repair.command-cvazbz99.js → repair.command-3r3j1xre.js} +7 -6
- package/{routeSourceValidator-6jd0q6r6.js → routeSourceValidator-4h947v7c.js} +13 -3
- package/{scalar.command-0acvyp26.js → scalar.command-e8y47j6d.js} +6 -5
- package/skills/akan-agent/SKILL.md +43 -0
- package/skills/akan-code/SKILL.md +38 -11
- package/skills/akan-debug/SKILL.md +41 -6
- package/skills/akan-deps/SKILL.md +1 -2
- package/skills/akan-err/SKILL.md +2 -1
- package/skills/akan-mcp/SKILL.md +40 -0
- package/skills/akan-page/SKILL.md +44 -0
- package/skills/akan-query/SKILL.md +39 -0
- package/skills/akan-runtime/SKILL.md +43 -0
- package/skills/akan-scaffold/SKILL.md +16 -6
- package/skills/akan-transport/SKILL.md +40 -0
- package/skills/akan-validate/SKILL.md +13 -11
- package/{subspace.command-822qx2bx.js → subspace.command-a1sf9n5a.js} +12 -10
- package/templates/__scalar/__model__/__model__.constant.ts +3 -5
- package/templates/__scalar/__model__/__model__.dictionary.ts +6 -5
- package/templates/__scalar/__model__/__model__.document.ts +3 -3
- package/templates/app/akan.config.ts +2 -3
- package/templates/app/env/env.client.ts +2 -4
- package/templates/app/env/env.client.type.ts +2 -3
- package/templates/app/env/env.server.ts +2 -3
- package/templates/app/lib/___appName__/__appName__.dictionary.ts +1 -2
- package/templates/app/lib/___appName__/__appName__.service.ts +3 -3
- package/templates/app/lib/___appName__/__appName__.signal.ts +5 -5
- package/templates/app/lib/___appName__/__appName__.store.ts +4 -6
- package/templates/app/lib/option.ts +2 -3
- package/templates/app/main.ts +2 -4
- package/templates/app/page/_index.tsx +3 -3
- package/templates/app/page/_layout.tsx +13 -10
- package/templates/appSample/lib/__scalar/workHistory/workHistory.constant.ts +1 -5
- package/templates/appSample/lib/__scalar/workHistory/workHistory.dictionary.ts +1 -1
- package/templates/appSample/lib/_noti/noti.signal.ts +1 -1
- package/templates/appSample/lib/task/Task.Template.tsx +2 -1
- package/templates/appSample/lib/task/Task.Unit.tsx +3 -2
- package/templates/appSample/lib/task/Task.Util.tsx +16 -4
- package/templates/appSample/lib/task/task.constant.ts +1 -5
- package/templates/appSample/lib/task/task.dictionary.ts +2 -8
- package/templates/appSample/lib/task/task.document.ts +1 -1
- package/templates/appSample/lib/task/task.signal.ts +14 -9
- package/templates/appSample/page/task/_index.tsx +2 -1
- package/templates/appSample/page/task/new.tsx +2 -1
- package/templates/appSample/srvkit/guards.ts +11 -0
- package/templates/appSample/ui/QuantityControl.tsx +5 -9
- package/templates/biomeForm.ts +144 -0
- package/templates/crudPages/[__model__Id]/edit/page.tsx +3 -3
- package/templates/crudPages/[__model__Id]/page.tsx +5 -5
- package/templates/crudPages/new/page.tsx +4 -3
- package/templates/crudPages/page.tsx +3 -3
- package/templates/crudSinglePage/page.tsx +9 -5
- package/templates/libRoot/akan.config.ts +2 -3
- package/templates/libRoot/lib/___libName__/__libName__.dictionary.ts +1 -2
- package/templates/libRoot/lib/___libName__/__libName__.service.ts +5 -4
- package/templates/libRoot/lib/___libName__/__libName__.signal.ts +6 -5
- package/templates/libRoot/lib/___libName__/__libName__.store.ts +5 -6
- package/templates/libRoot/lib/option.ts +1 -2
- package/templates/module/__Model__.Template.tsx +11 -10
- package/templates/module/__Model__.Unit.tsx +18 -5
- package/templates/module/__Model__.Util.tsx +9 -7
- package/templates/module/__Model__.View.tsx +9 -6
- package/templates/module/__Model__.Zone.tsx +25 -17
- package/templates/module/__model__.constant.ts +8 -9
- package/templates/module/__model__.dictionary.ts +16 -17
- package/templates/module/__model__.document.ts +6 -8
- package/templates/module/__model__.service.ts +3 -3
- package/templates/module/__model__.signal.ts +11 -10
- package/templates/module/__model__.store.ts +3 -5
- package/templates/service/__model__.dictionary.ts +5 -6
- package/templates/service/__model__.service.ts +3 -3
- package/templates/service/__model__.signal.ts +5 -4
- package/templates/service/__model__.store.ts +3 -5
- package/templates/workspaceRoot/.gitignore.template +4 -0
- package/templates/workspaceRoot/.vscode/settings.json.template +21 -21
- package/templates/workspaceRoot/AGENTS.md.template +4 -10
- package/{tunnel.command-ycmja19q.js → tunnel.command-dcb0wg93.js} +25 -13
- package/{typeChecker-px49mezc.js → typeChecker-j2jdnqsr.js} +1 -1
- package/typecheck.proc.js +6 -1
- package/verify.command-yyepccbh.js +93 -0
- package/{workflow.command-abb1d5xy.js → workflow.command-z5pg9ay0.js} +49 -14
- package/workspace.command-d7x5jttw.js +290 -0
- package/CodeAgent-8d5qs787.js +0 -9
- package/CodeAgentRpcListener-7p7z5dd7.js +0 -97
- package/TunnelShare-qkm8zp03.js +0 -14
- package/agent.command-ydftceda.js +0 -25
- package/cloud.script-nqevg5qw.js +0 -24
- package/code.command-9h3yrzhe.js +0 -167
- package/context.runner-8gg030b0.js +0 -25
- package/guidelines/conventions/conventions.instruction.md +0 -617
- package/guidelines/workspaceOnboarding/workspaceOnboarding.instruction.md +0 -291
- package/index-2mwc0g0d.js +0 -49
- package/index-4vgbysa0.js +0 -279
- package/index-7md2g9vw.js +0 -6
- package/index-b70zct19.js +0 -856
- package/index-c6eggbee.js +0 -123
- package/index-zzvvc845.js +0 -74
- package/quality.command-ah8qcakd.js +0 -1478
- package/templates/workspaceRoot/docs/AI-DEVELOPMENT.md.template +0 -69
- package/templates/workspaceRoot/docs/GENERATED.md.template +0 -55
- package/workspace.command-qm7cw29v.js +0 -521
|
@@ -2,10 +2,127 @@
|
|
|
2
2
|
import {
|
|
3
3
|
AppExecutor,
|
|
4
4
|
LibExecutor
|
|
5
|
-
} from "./index-
|
|
5
|
+
} from "./index-g500c5j9.js";
|
|
6
|
+
import {
|
|
7
|
+
createAst
|
|
8
|
+
} from "./index-2nxk8wgs.js";
|
|
9
|
+
import {
|
|
10
|
+
camelToKebabCase
|
|
11
|
+
} from "./index-9zy8479y.js";
|
|
6
12
|
|
|
7
13
|
// pkgs/@akanjs/devkit/workflow/artifacts.ts
|
|
8
|
-
import { capitalize } from "akanjs/common";
|
|
14
|
+
import { capitalize as capitalize2 } from "akanjs/common";
|
|
15
|
+
|
|
16
|
+
// pkgs/@akanjs/devkit/workflow/interactionScaffold.ts
|
|
17
|
+
import { capitalize, lowerlize } from "akanjs/common";
|
|
18
|
+
|
|
19
|
+
class InteractionScaffold {
|
|
20
|
+
name;
|
|
21
|
+
className;
|
|
22
|
+
hookName;
|
|
23
|
+
#commonSpecifier;
|
|
24
|
+
constructor(sys, name) {
|
|
25
|
+
this.name = name;
|
|
26
|
+
this.className = capitalize(name);
|
|
27
|
+
this.hookName = `use${this.className}`;
|
|
28
|
+
this.#commonSpecifier = `@${sys.type}s/${sys.name}/common`;
|
|
29
|
+
}
|
|
30
|
+
static nameOf(raw) {
|
|
31
|
+
const name = lowerlize(raw.replace(/^use(?=[A-Z])/, ""));
|
|
32
|
+
return /^[a-z][A-Za-z0-9]*$/.test(name) ? name : null;
|
|
33
|
+
}
|
|
34
|
+
static async build(sys, raw) {
|
|
35
|
+
const diagnostics = [];
|
|
36
|
+
const name = raw ? InteractionScaffold.nameOf(raw) : null;
|
|
37
|
+
if (!name) {
|
|
38
|
+
diagnostics.push({
|
|
39
|
+
severity: "error",
|
|
40
|
+
code: "create-interaction-name-invalid",
|
|
41
|
+
input: "interaction",
|
|
42
|
+
message: `Interaction name "${raw ?? ""}" must be camelCase (boardKeys), optionally prefixed with use.`
|
|
43
|
+
});
|
|
44
|
+
return { diagnostics, files: [] };
|
|
45
|
+
}
|
|
46
|
+
const scaffold = new InteractionScaffold(sys, name);
|
|
47
|
+
const files = scaffold.files;
|
|
48
|
+
const taken = (await Promise.all(scaffold.claimedPaths.map(async (path) => await sys.exists(path) ? `${sys.type}s/${sys.name}/${path}` : null))).filter((path) => !!path);
|
|
49
|
+
if (taken.length)
|
|
50
|
+
diagnostics.push({
|
|
51
|
+
severity: "error",
|
|
52
|
+
code: "create-interaction-exists",
|
|
53
|
+
input: "interaction",
|
|
54
|
+
message: `${taken.join(", ")} already exists; pick another interaction name or extend the existing files.`
|
|
55
|
+
});
|
|
56
|
+
return { diagnostics, files: taken.length ? [] : files };
|
|
57
|
+
}
|
|
58
|
+
get claimedPaths() {
|
|
59
|
+
const { name, hookName } = this;
|
|
60
|
+
return [
|
|
61
|
+
`common/${name}.ts`,
|
|
62
|
+
`common/${name}.tsx`,
|
|
63
|
+
`common/${name}.test.ts`,
|
|
64
|
+
`webkit/${hookName}.tsx`,
|
|
65
|
+
`webkit/${hookName}.ts`
|
|
66
|
+
];
|
|
67
|
+
}
|
|
68
|
+
get files() {
|
|
69
|
+
return [
|
|
70
|
+
{
|
|
71
|
+
path: `common/${this.name}.ts`,
|
|
72
|
+
content: this.logicSource,
|
|
73
|
+
action: "create",
|
|
74
|
+
reason: "Pure interaction logic."
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
path: `common/${this.name}.test.ts`,
|
|
78
|
+
content: this.testSource,
|
|
79
|
+
action: "create",
|
|
80
|
+
reason: "Test of the pure interaction logic."
|
|
81
|
+
},
|
|
82
|
+
{ path: `webkit/${this.hookName}.tsx`, content: this.hookSource, action: "create", reason: "Client hook." }
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
get logicSource() {
|
|
86
|
+
return [
|
|
87
|
+
`export class ${this.className} {`,
|
|
88
|
+
" static next<State extends object>(state: State, input: Partial<State>) {",
|
|
89
|
+
" return { ...state, ...input };",
|
|
90
|
+
" }",
|
|
91
|
+
"}",
|
|
92
|
+
""
|
|
93
|
+
].join(`
|
|
94
|
+
`);
|
|
95
|
+
}
|
|
96
|
+
get testSource() {
|
|
97
|
+
return [
|
|
98
|
+
'import { describe, expect, it } from "bun:test";',
|
|
99
|
+
`import { ${this.className} } from "./${this.name}";`,
|
|
100
|
+
"",
|
|
101
|
+
`describe(${JSON.stringify(this.className)}, () => {`,
|
|
102
|
+
' it("applies an input over the state it is handed", () => {',
|
|
103
|
+
` expect(${this.className}.next({ idx: 0, isOpen: false }, { idx: 1 })).toEqual({ idx: 1, isOpen: false });`,
|
|
104
|
+
" });",
|
|
105
|
+
"});",
|
|
106
|
+
""
|
|
107
|
+
].join(`
|
|
108
|
+
`);
|
|
109
|
+
}
|
|
110
|
+
get hookSource() {
|
|
111
|
+
return [
|
|
112
|
+
'"use client";',
|
|
113
|
+
`import { ${this.className} } from "${this.#commonSpecifier}";`,
|
|
114
|
+
"",
|
|
115
|
+
`export const ${this.hookName} = <State extends object>(state: State, commit: (next: State) => void) => {`,
|
|
116
|
+
" const change = async (input: Partial<State>) => {",
|
|
117
|
+
` commit(${this.className}.next(state, input));`,
|
|
118
|
+
" };",
|
|
119
|
+
" return { change };",
|
|
120
|
+
"};",
|
|
121
|
+
""
|
|
122
|
+
].join(`
|
|
123
|
+
`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
9
126
|
|
|
10
127
|
// pkgs/@akanjs/devkit/workflow/utils.ts
|
|
11
128
|
var jsonText = (value, { trailingNewline = true } = {}) => `${JSON.stringify(value, null, 2)}${trailingNewline ? `
|
|
@@ -114,8 +231,10 @@ var planInputString = (plan, key) => {
|
|
|
114
231
|
var workflowPathsForPlan = (plan) => {
|
|
115
232
|
const app = planInputString(plan, "app");
|
|
116
233
|
const module = planInputString(plan, "module");
|
|
117
|
-
const moduleClass = module ?
|
|
118
|
-
|
|
234
|
+
const moduleClass = module ? capitalize2(module) : "<Module>";
|
|
235
|
+
const rawInteraction = planInputString(plan, "interaction");
|
|
236
|
+
const interaction = rawInteraction ? InteractionScaffold.nameOf(rawInteraction) ?? rawInteraction : null;
|
|
237
|
+
return plan.predictedChanges.map((change) => change.target.replace(/^\*\//, app ? `apps/${app}/` : "").replaceAll("<module>", module || "<module>").replaceAll("<Module>", moduleClass).replaceAll("<interaction>", interaction || "<interaction>").replaceAll("<Interaction>", interaction ? capitalize2(interaction) : "<Interaction>"));
|
|
119
238
|
};
|
|
120
239
|
var workflowRunsDir = ".akan/workflows/runs";
|
|
121
240
|
var createWorkflowRunId = (prefix = "run") => `${prefix}-${new Date().toISOString().replace(/[-:.TZ]/g, "").slice(0, 14)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
@@ -174,6 +293,14 @@ var statusForValidationKind = (commands, kind) => {
|
|
|
174
293
|
return "unknown";
|
|
175
294
|
return matching.some((command) => command.status === "failed") ? "failed" : "passed";
|
|
176
295
|
};
|
|
296
|
+
var generatedSyncStatus = (commands) => {
|
|
297
|
+
const sync = statusForValidationKind(commands, "sync");
|
|
298
|
+
const verify = commands.filter((command) => command.kind === "verify");
|
|
299
|
+
if (sync !== "unknown" || verify.length === 0)
|
|
300
|
+
return sync;
|
|
301
|
+
const syncFailed = verify.some((command) => /^verify fail \u00B7 .*\bsync \d+ errors?\b/m.test(command.stdout ?? ""));
|
|
302
|
+
return syncFailed ? "failed" : "passed";
|
|
303
|
+
};
|
|
177
304
|
var statusForCommands = (commands) => {
|
|
178
305
|
if (commands.length === 0)
|
|
179
306
|
return "unknown";
|
|
@@ -267,7 +394,7 @@ var createValidationStatuses = (commands, reportDiagnostics, baselineDiagnostics
|
|
|
267
394
|
overallStatus,
|
|
268
395
|
summary: {
|
|
269
396
|
sourceChange: sourceStatus,
|
|
270
|
-
generatedSync:
|
|
397
|
+
generatedSync: generatedSyncStatus(commands),
|
|
271
398
|
validationCommands: validationCommandsStatus,
|
|
272
399
|
baseline: baselineStatus,
|
|
273
400
|
workspaceConfig: statusForScope(commands, diagnostics, scopes, "workspace-config"),
|
|
@@ -386,7 +513,7 @@ var createRepairReport = ({
|
|
|
386
513
|
...syncedAt ? { syncedAt } : {}
|
|
387
514
|
});
|
|
388
515
|
// pkgs/@akanjs/devkit/workflow/executor.ts
|
|
389
|
-
import { capitalize as
|
|
516
|
+
import { capitalize as capitalize3 } from "akanjs/common";
|
|
390
517
|
import ts4 from "typescript";
|
|
391
518
|
|
|
392
519
|
// pkgs/@akanjs/devkit/workflow/moduleIndex.ts
|
|
@@ -395,55 +522,20 @@ import path from "path";
|
|
|
395
522
|
import ts3 from "typescript";
|
|
396
523
|
|
|
397
524
|
// pkgs/@akanjs/devkit/workflow/source.ts
|
|
398
|
-
import { lowerlize } from "akanjs/common";
|
|
525
|
+
import { lowerlize as lowerlize2 } from "akanjs/common";
|
|
399
526
|
import ts2 from "typescript";
|
|
400
527
|
|
|
401
528
|
// pkgs/@akanjs/devkit/workflow/sourceAst.ts
|
|
402
529
|
import ts from "typescript";
|
|
403
|
-
var
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
var expressionName = (expression) => {
|
|
413
|
-
if (ts.isIdentifier(expression))
|
|
414
|
-
return expression.text;
|
|
415
|
-
if (ts.isPropertyAccessExpression(expression))
|
|
416
|
-
return expression.name.text;
|
|
417
|
-
if (ts.isCallExpression(expression))
|
|
418
|
-
return expressionName(expression.expression);
|
|
419
|
-
if (ts.isAsExpression(expression))
|
|
420
|
-
return expressionName(expression.expression);
|
|
421
|
-
return null;
|
|
422
|
-
};
|
|
423
|
-
var callExpressionName = (node) => ts.isPropertyAccessExpression(node.expression) ? node.expression.name.text : expressionName(node.expression);
|
|
424
|
-
var firstObjectReturnedByArrow = (node) => {
|
|
425
|
-
if (!ts.isArrowFunction(node) && !ts.isFunctionExpression(node))
|
|
426
|
-
return null;
|
|
427
|
-
if (ts.isObjectLiteralExpression(node.body))
|
|
428
|
-
return node.body;
|
|
429
|
-
if (ts.isParenthesizedExpression(node.body) && ts.isObjectLiteralExpression(node.body.expression)) {
|
|
430
|
-
return node.body.expression;
|
|
431
|
-
}
|
|
432
|
-
if (!ts.isBlock(node.body))
|
|
433
|
-
return null;
|
|
434
|
-
for (const statement of node.body.statements) {
|
|
435
|
-
if (ts.isReturnStatement(statement) && statement.expression && ts.isObjectLiteralExpression(statement.expression)) {
|
|
436
|
-
return statement.expression;
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
return null;
|
|
440
|
-
};
|
|
441
|
-
var isViaCall = (expression) => ts.isCallExpression(expression) && expressionName(expression.expression) === "via";
|
|
442
|
-
var heritageCall = (node) => {
|
|
443
|
-
const heritage = node.heritageClauses?.flatMap((clause) => [...clause.types]) ?? [];
|
|
444
|
-
const expression = heritage.find((clause) => isViaCall(clause.expression))?.expression;
|
|
445
|
-
return expression && ts.isCallExpression(expression) ? expression : null;
|
|
446
|
-
};
|
|
530
|
+
var {
|
|
531
|
+
sourceFileFor,
|
|
532
|
+
nodeName,
|
|
533
|
+
propertyName,
|
|
534
|
+
expressionName,
|
|
535
|
+
callExpressionName,
|
|
536
|
+
firstObjectReturnedByArrow,
|
|
537
|
+
heritageCall
|
|
538
|
+
} = createAst(ts);
|
|
447
539
|
|
|
448
540
|
// pkgs/@akanjs/devkit/workflow/source.ts
|
|
449
541
|
var getSysRoot = (sys) => `${sys.type}s/${sys.name}`;
|
|
@@ -459,6 +551,7 @@ var moduleSourcePaths = (moduleName) => {
|
|
|
459
551
|
abstract: `lib/${moduleName}/${moduleName}.abstract.md`,
|
|
460
552
|
constant: `lib/${moduleName}/${moduleName}.constant.ts`,
|
|
461
553
|
dictionary: `lib/${moduleName}/${moduleName}.dictionary.ts`,
|
|
554
|
+
document: `lib/${moduleName}/${moduleName}.document.ts`,
|
|
462
555
|
service: `lib/${moduleName}/${moduleName}.service.ts`,
|
|
463
556
|
signal: `lib/${moduleName}/${moduleName}.signal.ts`,
|
|
464
557
|
store: `lib/${moduleName}/${moduleName}.store.ts`,
|
|
@@ -471,12 +564,10 @@ var moduleSourcePaths = (moduleName) => {
|
|
|
471
564
|
};
|
|
472
565
|
var generatedFilesForSync = (sys, reason = "Generated files may change after sync.") => generatedFilePathsForTarget(getSysRoot(sys), reason);
|
|
473
566
|
var validationCommandsForTarget = (target) => [
|
|
474
|
-
{ command: `akan
|
|
475
|
-
{ command: `akan lint ${target}`, reason: "Validate formatting, imports, and static lint rules." }
|
|
567
|
+
{ command: `akan verify ${target}`, reason: "Sync, lint, typecheck and build the target in one run." }
|
|
476
568
|
];
|
|
477
569
|
var nextActionsForTarget = (target) => [
|
|
478
|
-
{ command: `akan
|
|
479
|
-
{ command: `akan lint ${target}`, reason: "Validate the target after generated files are refreshed." }
|
|
570
|
+
{ command: `akan verify ${target}`, reason: "Refresh generated files and validate the target in one run." }
|
|
480
571
|
];
|
|
481
572
|
var createPrimitiveWriteReport = ({
|
|
482
573
|
command,
|
|
@@ -542,7 +633,7 @@ var koLabelForField = (fieldName) => {
|
|
|
542
633
|
if (koLabels[fieldName])
|
|
543
634
|
return koLabels[fieldName];
|
|
544
635
|
const words = splitFieldWords(fieldName);
|
|
545
|
-
const translated = words.map((word) => koLabels[word] ?? koLabels[
|
|
636
|
+
const translated = words.map((word) => koLabels[word] ?? koLabels[lowerlize2(word)] ?? null);
|
|
546
637
|
return translated.every(Boolean) ? translated.join(" ") : null;
|
|
547
638
|
};
|
|
548
639
|
var bilingualLabelForField = (fieldName) => {
|
|
@@ -569,17 +660,48 @@ var normalizeFieldType = (typeName) => {
|
|
|
569
660
|
};
|
|
570
661
|
return normalizedTypes[typeName.toLowerCase()] ?? typeName;
|
|
571
662
|
};
|
|
663
|
+
var importOrder = (a, b) => {
|
|
664
|
+
const [lowerA, lowerB] = [a.toLowerCase(), b.toLowerCase()];
|
|
665
|
+
if (lowerA !== lowerB)
|
|
666
|
+
return lowerA < lowerB ? -1 : 1;
|
|
667
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
668
|
+
};
|
|
572
669
|
var ensureNamedImport = (content, moduleSpecifier, name) => {
|
|
573
670
|
const source = sourceFileFor("source.ts", content);
|
|
574
|
-
const namedImport = findNamedImport(source, moduleSpecifier);
|
|
575
|
-
if (namedImport)
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
|
|
671
|
+
const namedImport = findNamedImport(source, moduleSpecifier, { valueOnly: true });
|
|
672
|
+
if (!namedImport)
|
|
673
|
+
return ensureImportDeclaration(content, moduleSpecifier, `{ ${name} }`);
|
|
674
|
+
if (namedImport.names.includes(name))
|
|
675
|
+
return content;
|
|
676
|
+
const nextElements = [...namedImport.elements, { name, text: name }].sort((a, b) => importOrder(a.name, b.name));
|
|
677
|
+
return spliceText(content, namedImport.namedBindingsStart, namedImport.namedBindingsEnd, `{ ${nextElements.map((element) => element.text).join(", ")} }`);
|
|
678
|
+
};
|
|
679
|
+
var ensureImportDeclaration = (content, moduleSpecifier, clause) => {
|
|
680
|
+
const line = `import ${clause} from "${moduleSpecifier}";`;
|
|
681
|
+
if (content.includes(line))
|
|
682
|
+
return content;
|
|
683
|
+
const source = sourceFileFor("source.ts", content);
|
|
684
|
+
const imports = source.statements.filter((statement) => ts2.isImportDeclaration(statement)).flatMap((statement) => ts2.isStringLiteral(statement.moduleSpecifier) ? [{ specifier: statement.moduleSpecifier.text, start: statement.getStart(source), end: statement.getEnd() }] : []);
|
|
685
|
+
const isRelative = (specifier) => specifier.startsWith(".");
|
|
686
|
+
const peers = imports.filter((entry) => isRelative(entry.specifier) === isRelative(moduleSpecifier));
|
|
687
|
+
const before = peers.find((entry) => importOrder(entry.specifier, moduleSpecifier) > 0);
|
|
688
|
+
if (before) {
|
|
689
|
+
const insertAt = lineStartAt(content, before.start);
|
|
690
|
+
return spliceText(content, insertAt, insertAt, `${line}
|
|
691
|
+
`);
|
|
692
|
+
}
|
|
693
|
+
const after = peers.at(-1) ?? (isRelative(moduleSpecifier) ? imports.at(-1) : undefined);
|
|
694
|
+
if (after) {
|
|
695
|
+
const insertAt = lineEndAt(content, after.end);
|
|
696
|
+
return spliceText(content, insertAt, insertAt, peers.length ? `${line}
|
|
697
|
+
` : `
|
|
698
|
+
${line}
|
|
699
|
+
`);
|
|
700
|
+
}
|
|
701
|
+
const insertAt = imports[0] ? lineStartAt(content, imports[0].start) : 0;
|
|
702
|
+
return spliceText(content, insertAt, insertAt, `${line}
|
|
703
|
+
|
|
704
|
+
`);
|
|
583
705
|
};
|
|
584
706
|
var ensureBaseImport = (content, name) => ensureNamedImport(content, "akanjs/base", name);
|
|
585
707
|
var ensureBaseTypeImport = (content, typeName) => {
|
|
@@ -800,17 +922,18 @@ var dictionaryChainOrderValid = (chainMethods) => {
|
|
|
800
922
|
}
|
|
801
923
|
return true;
|
|
802
924
|
};
|
|
803
|
-
var findDictionaryModelObject = (source, moduleClassName) =>
|
|
925
|
+
var findDictionaryModelObject = (source, moduleClassName) => findDictionaryStageObject(source, "model", moduleClassName);
|
|
926
|
+
var findDictionaryStageObject = (source, stage, typeName) => {
|
|
804
927
|
let locator = null;
|
|
805
928
|
const visit = (node) => {
|
|
806
929
|
if (locator)
|
|
807
930
|
return;
|
|
808
|
-
if (!ts2.isCallExpression(node) || callExpressionName(node) !==
|
|
931
|
+
if (!ts2.isCallExpression(node) || callExpressionName(node) !== stage) {
|
|
809
932
|
ts2.forEachChild(node, visit);
|
|
810
933
|
return;
|
|
811
934
|
}
|
|
812
935
|
const typeArgument = node.typeArguments?.[0];
|
|
813
|
-
if (!typeArgument || typeArgument.getText(source) !==
|
|
936
|
+
if (!typeArgument || typeArgument.getText(source) !== typeName) {
|
|
814
937
|
ts2.forEachChild(node, visit);
|
|
815
938
|
return;
|
|
816
939
|
}
|
|
@@ -852,17 +975,20 @@ var findLightProjectionArray = (source, moduleClassName) => {
|
|
|
852
975
|
ts2.forEachChild(source, visit);
|
|
853
976
|
return locator;
|
|
854
977
|
};
|
|
855
|
-
var findNamedImport = (source, moduleSpecifier) => {
|
|
978
|
+
var findNamedImport = (source, moduleSpecifier, { valueOnly = false } = {}) => {
|
|
856
979
|
for (const statement of source.statements) {
|
|
857
980
|
if (!ts2.isImportDeclaration(statement) || !ts2.isStringLiteral(statement.moduleSpecifier))
|
|
858
981
|
continue;
|
|
859
982
|
if (statement.moduleSpecifier.text !== moduleSpecifier)
|
|
860
983
|
continue;
|
|
984
|
+
if (valueOnly && statement.importClause?.isTypeOnly)
|
|
985
|
+
continue;
|
|
861
986
|
const namedBindings = statement.importClause?.namedBindings;
|
|
862
987
|
if (!namedBindings || !ts2.isNamedImports(namedBindings))
|
|
863
988
|
continue;
|
|
864
989
|
return {
|
|
865
990
|
names: namedBindings.elements.map((element) => element.name.text),
|
|
991
|
+
elements: namedBindings.elements.map((element) => ({ name: element.name.text, text: element.getText(source) })),
|
|
866
992
|
namedBindingsStart: namedBindings.getStart(source),
|
|
867
993
|
namedBindingsEnd: namedBindings.getEnd()
|
|
868
994
|
};
|
|
@@ -1090,6 +1216,17 @@ var hasDictionaryModelField = (content, moduleClassName, fieldName) => {
|
|
|
1090
1216
|
return false;
|
|
1091
1217
|
return findDictionaryModelObject(source, moduleClassName)?.fields.some((field) => field.name === fieldName) ?? false;
|
|
1092
1218
|
};
|
|
1219
|
+
var hasDictionaryEndpointEntry = (content, moduleClassName, entryName) => {
|
|
1220
|
+
const source = sourceFileFor("dictionary.ts", content);
|
|
1221
|
+
return findDictionaryStageObject(source, "endpoint", `${moduleClassName}Endpoint`)?.fields.some((field) => field.name === entryName) ?? false;
|
|
1222
|
+
};
|
|
1223
|
+
var insertDictionaryEndpointEntry = (content, moduleClassName, entryName, entryText) => {
|
|
1224
|
+
const source = sourceFileFor("dictionary.ts", content);
|
|
1225
|
+
const locator = findDictionaryStageObject(source, "endpoint", `${moduleClassName}Endpoint`);
|
|
1226
|
+
if (!locator)
|
|
1227
|
+
return null;
|
|
1228
|
+
return insertOrderedFieldLine(content, locator, entryName, entryText, { fieldIndent: " ", closingIndent: " " });
|
|
1229
|
+
};
|
|
1093
1230
|
var ensureConstantTypeImport = (content, constantPath, typeName) => {
|
|
1094
1231
|
if (new RegExp(`import type \\{[^}]*\\b${typeName}\\b[^}]*\\} from "${constantPath}";`).test(content))
|
|
1095
1232
|
return content;
|
|
@@ -1102,19 +1239,41 @@ var ensureConstantTypeImport = (content, constantPath, typeName) => {
|
|
|
1102
1239
|
return `import type { ${typeName} } from "${constantPath}";
|
|
1103
1240
|
${content}`;
|
|
1104
1241
|
};
|
|
1242
|
+
var dictionaryChainOf = (node) => {
|
|
1243
|
+
if (ts2.isCallExpression(node) && outermostFluentCall(node) === node && protectedDictionaryChainOrder.some((method) => chainMethodsForCall(node).includes(method)))
|
|
1244
|
+
return node;
|
|
1245
|
+
return ts2.forEachChild(node, dictionaryChainOf);
|
|
1246
|
+
};
|
|
1247
|
+
var chainMethodNames = (call) => {
|
|
1248
|
+
if (!ts2.isCallExpression(call) || !ts2.isPropertyAccessExpression(call.expression))
|
|
1249
|
+
return [];
|
|
1250
|
+
const name = call.expression.name;
|
|
1251
|
+
return [...chainMethodNames(call.expression.expression), ...ts2.isIdentifier(name) ? [name] : []];
|
|
1252
|
+
};
|
|
1105
1253
|
var insertDictionaryEnum = (content, enumClassName, enumName, values) => {
|
|
1106
1254
|
if (content.includes(`.enum<${enumClassName}>("${enumName}"`))
|
|
1107
1255
|
return content;
|
|
1256
|
+
const source = sourceFileFor("dictionary.ts", content);
|
|
1257
|
+
if (hasParseDiagnostics(source))
|
|
1258
|
+
return null;
|
|
1259
|
+
const chain = dictionaryChainOf(source);
|
|
1260
|
+
if (!chain)
|
|
1261
|
+
return null;
|
|
1108
1262
|
const enumBlock = ` .enum<${enumClassName}>("${enumName}", (t) => ({
|
|
1109
1263
|
${values.map((value) => ` ${value}: t([${JSON.stringify(titleize(value))}, ${JSON.stringify(titleize(value))}]),`).join(`
|
|
1110
1264
|
`)}
|
|
1111
1265
|
}))
|
|
1112
1266
|
`;
|
|
1113
|
-
const
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1267
|
+
const later = chainMethodNames(chain).find((name) => name.text === "error" || name.text === "translate");
|
|
1268
|
+
if (!later)
|
|
1269
|
+
return spliceText(content, chain.getEnd(), chain.getEnd(), `
|
|
1270
|
+
${enumBlock.trimEnd()}`);
|
|
1271
|
+
const dot = content.lastIndexOf(".", later.getStart(source));
|
|
1272
|
+
const lineStart = lineStartAt(content, dot);
|
|
1273
|
+
if (content.slice(lineStart, dot).trim() === "")
|
|
1274
|
+
return spliceText(content, lineStart, lineStart, enumBlock);
|
|
1275
|
+
return spliceText(content, dot, dot, `
|
|
1276
|
+
${enumBlock}`);
|
|
1118
1277
|
};
|
|
1119
1278
|
var parseValues = (value) => value?.split(",").map((item) => item.trim()).filter(Boolean) ?? [];
|
|
1120
1279
|
var hasSourceParseErrors = (content, fileName = "source.ts") => hasParseDiagnostics(sourceFileFor(fileName, content));
|
|
@@ -1144,6 +1303,14 @@ var hasClassMethod = (content, className, methodName) => {
|
|
|
1144
1303
|
const node = findClassDeclaration(sourceFileFor("service.ts", content), className);
|
|
1145
1304
|
return Boolean(node?.members.some((member) => ts2.isMethodDeclaration(member) && nodeName(member.name) === methodName));
|
|
1146
1305
|
};
|
|
1306
|
+
var classMethodParameters = (content, className, methodName) => {
|
|
1307
|
+
const source = sourceFileFor("service.ts", content);
|
|
1308
|
+
const method = findClassDeclaration(source, className)?.members.find((member) => ts2.isMethodDeclaration(member) && nodeName(member.name) === methodName);
|
|
1309
|
+
return method?.parameters.map((parameter) => ({
|
|
1310
|
+
name: nodeName(parameter.name),
|
|
1311
|
+
optional: !!parameter.questionToken || !!parameter.initializer || !!parameter.dotDotDotToken
|
|
1312
|
+
})) ?? null;
|
|
1313
|
+
};
|
|
1147
1314
|
var insertClassMethod = (content, className, methodBlock) => {
|
|
1148
1315
|
const source = sourceFileFor("service.ts", content);
|
|
1149
1316
|
const node = findClassDeclaration(source, className);
|
|
@@ -1228,6 +1395,33 @@ var insertSignalFactoryEntry = (content, className, entryName, entryLine, param)
|
|
|
1228
1395
|
return null;
|
|
1229
1396
|
return paramEdit === "unchanged" ? withEntry : spliceText(withEntry, paramEdit.start, paramEdit.end, paramEdit.text);
|
|
1230
1397
|
};
|
|
1398
|
+
var appendTopLevelTestCases = (content, describeTitle, render) => {
|
|
1399
|
+
const bunImport = findNamedImport(sourceFileFor("test.ts", content), "bun:test", { valueOnly: true });
|
|
1400
|
+
const itName = !bunImport?.names.includes("it") && bunImport?.names.includes("test") ? "test" : "it";
|
|
1401
|
+
const imported = ensureNamedImport(content, "bun:test", itName);
|
|
1402
|
+
const source = sourceFileFor("test.ts", imported);
|
|
1403
|
+
const body = source.statements.flatMap((statement) => {
|
|
1404
|
+
if (!ts2.isExpressionStatement(statement) || !ts2.isCallExpression(statement.expression))
|
|
1405
|
+
return [];
|
|
1406
|
+
if (expressionName(statement.expression.expression) !== "describe")
|
|
1407
|
+
return [];
|
|
1408
|
+
const callback = factoryArrowOf(statement.expression);
|
|
1409
|
+
return callback && ts2.isBlock(callback.body) ? [callback.body] : [];
|
|
1410
|
+
})[0];
|
|
1411
|
+
if (!body) {
|
|
1412
|
+
const block = [`describe(${JSON.stringify(describeTitle)}, () => {`, ...render(itName, " "), "});", ""];
|
|
1413
|
+
return `${ensureNamedImport(imported, "bun:test", "describe").trimEnd()}
|
|
1414
|
+
|
|
1415
|
+
${block.join(`
|
|
1416
|
+
`)}`;
|
|
1417
|
+
}
|
|
1418
|
+
const firstStatement = body.statements[0];
|
|
1419
|
+
const indent = firstStatement ? lineIndentAt(imported, firstStatement.getStart(source)) : `${lineIndentAt(imported, body.getStart(source))} `;
|
|
1420
|
+
const insertAt = lineStartAt(imported, body.getEnd() - 1);
|
|
1421
|
+
return spliceText(imported, insertAt, insertAt, `${render(itName, indent).join(`
|
|
1422
|
+
`)}
|
|
1423
|
+
`);
|
|
1424
|
+
};
|
|
1231
1425
|
|
|
1232
1426
|
// pkgs/@akanjs/devkit/workflow/moduleIndex.ts
|
|
1233
1427
|
var indexFileKinds = [
|
|
@@ -1891,10 +2085,10 @@ var addMutationActionSurfaceInspection = (plan) => {
|
|
|
1891
2085
|
const moduleClassName = moduleComponentName(module);
|
|
1892
2086
|
return surfaceReview(plan, {
|
|
1893
2087
|
code: "add-mutation-action-surface-review",
|
|
1894
|
-
target: `*/${moduleSourcePaths(module).
|
|
1895
|
-
action: `
|
|
1896
|
-
message: `Workflow apply does not write
|
|
1897
|
-
reason: "Review action surface guidance before manually editing
|
|
2088
|
+
target: `*/${moduleSourcePaths(module).util}`,
|
|
2089
|
+
action: `Fill the ${moduleClassName} chain method (validate, mutate, return this) and replace its transition comment. After sync, call st.do.${mutation}(id) from the control in ${moduleClassName}.Util.tsx; a second write that must land with it is another with/after entry, never a second fetch in the store action.`,
|
|
2090
|
+
message: `Workflow apply does not write UI code for ${module}.${mutation}; review which screen calls it.`,
|
|
2091
|
+
reason: "Review action surface guidance before manually editing UI files."
|
|
1898
2092
|
});
|
|
1899
2093
|
};
|
|
1900
2094
|
var addSliceViewSurfaceInspection = (plan) => {
|
|
@@ -1904,7 +2098,7 @@ var addSliceViewSurfaceInspection = (plan) => {
|
|
|
1904
2098
|
return surfaceReview(plan, {
|
|
1905
2099
|
code: "add-slice-view-surface-review",
|
|
1906
2100
|
target: `*/${moduleSourcePaths(module).zone}`,
|
|
1907
|
-
action: `Fill in the service query stub and add the dictionary .slice() entry. After sync, load fetch.init${moduleClassName}${
|
|
2101
|
+
action: `Fill in the service query stub and add the dictionary .slice() entry. After sync, load fetch.init${moduleClassName}${capitalize3(slice)}() in the page and pass the result to a ${moduleClassName}.Zone as an init prop.`,
|
|
1908
2102
|
message: `Workflow apply does not write page or Zone code for ${module}.${slice}; review where the list should render.`,
|
|
1909
2103
|
reason: "Review view surface guidance before manually editing Zone or page files."
|
|
1910
2104
|
});
|
|
@@ -1917,7 +2111,8 @@ var createWorkflowStepRegistry = ({
|
|
|
1917
2111
|
addField,
|
|
1918
2112
|
addEnumField,
|
|
1919
2113
|
addMutation,
|
|
1920
|
-
addSlice
|
|
2114
|
+
addSlice,
|
|
2115
|
+
createInteraction
|
|
1921
2116
|
}) => {
|
|
1922
2117
|
const inspect = async () => {
|
|
1923
2118
|
return;
|
|
@@ -1994,13 +2189,24 @@ var createWorkflowStepRegistry = ({
|
|
|
1994
2189
|
})),
|
|
1995
2190
|
[workflowStepKey("add-enum-field", "update-dictionary")]: inspect,
|
|
1996
2191
|
[workflowStepKey("add-enum-field", "update-option")]: inspect,
|
|
1997
|
-
[workflowStepKey("add-mutation", "update-
|
|
2192
|
+
[workflowStepKey("add-mutation", "update-document")]: async (_step, plan) => primitiveReportToWorkflowStepResult(await addMutation({
|
|
1998
2193
|
app: workflowStringInput(plan.inputs.app),
|
|
1999
2194
|
module: workflowStringInput(plan.inputs.module),
|
|
2000
|
-
mutation: workflowStringInput(plan.inputs.mutation)
|
|
2195
|
+
mutation: workflowStringInput(plan.inputs.mutation),
|
|
2196
|
+
guards: workflowStringArrayInput(plan.inputs.guard),
|
|
2197
|
+
withCalls: workflowStringArrayInput(plan.inputs.with),
|
|
2198
|
+
afterCalls: workflowStringArrayInput(plan.inputs.after)
|
|
2001
2199
|
})),
|
|
2200
|
+
[workflowStepKey("add-mutation", "update-service")]: inspect,
|
|
2002
2201
|
[workflowStepKey("add-mutation", "update-signal")]: inspect,
|
|
2003
|
-
[workflowStepKey("add-mutation", "update-
|
|
2202
|
+
[workflowStepKey("add-mutation", "update-store")]: inspect,
|
|
2203
|
+
[workflowStepKey("add-mutation", "update-dictionary")]: inspect,
|
|
2204
|
+
[workflowStepKey("add-mutation", "add-signal-test")]: inspect,
|
|
2205
|
+
[workflowStepKey("add-mutation", "connect-action-ui")]: async (_step, plan) => addMutationActionSurfaceInspection(plan),
|
|
2206
|
+
[workflowStepKey("create-interaction", "create-interaction")]: async (_step, plan) => primitiveReportToWorkflowStepResult(await createInteraction({
|
|
2207
|
+
app: workflowStringInput(plan.inputs.app),
|
|
2208
|
+
interaction: workflowStringInput(plan.inputs.interaction)
|
|
2209
|
+
})),
|
|
2004
2210
|
[workflowStepKey("add-slice", "update-service-query")]: async (_step, plan) => primitiveReportToWorkflowStepResult(await addSlice({
|
|
2005
2211
|
app: workflowStringInput(plan.inputs.app),
|
|
2006
2212
|
module: workflowStringInput(plan.inputs.module),
|
|
@@ -2084,9 +2290,654 @@ class WorkflowExecutor {
|
|
|
2084
2290
|
return report();
|
|
2085
2291
|
}
|
|
2086
2292
|
}
|
|
2293
|
+
// pkgs/@akanjs/devkit/workflow/guardCatalog.ts
|
|
2294
|
+
class GuardCatalog {
|
|
2295
|
+
static frameworkGuards = ["Public"];
|
|
2296
|
+
static #actingArgOf = new Map([
|
|
2297
|
+
["User", { argName: "Self", param: "self", value: "self.id", serviceParam: "selfId" }],
|
|
2298
|
+
[
|
|
2299
|
+
"SignedIn",
|
|
2300
|
+
{ argName: "CurrentUserId", param: "currentUserId", value: "currentUserId", serviceParam: "currentUserId" }
|
|
2301
|
+
]
|
|
2302
|
+
]);
|
|
2303
|
+
#guards;
|
|
2304
|
+
#internalArgs;
|
|
2305
|
+
reachedLibs;
|
|
2306
|
+
constructor(guards, internalArgs, reachedLibs) {
|
|
2307
|
+
this.#guards = guards;
|
|
2308
|
+
this.#internalArgs = internalArgs;
|
|
2309
|
+
this.reachedLibs = reachedLibs;
|
|
2310
|
+
}
|
|
2311
|
+
static async load(sys) {
|
|
2312
|
+
const reachedLibs = await GuardCatalog.#reachedLibs(sys);
|
|
2313
|
+
const scopes = [{ type: sys.type, name: sys.name }, ...reachedLibs.map((name) => ({ type: "lib", name }))];
|
|
2314
|
+
const exports = (await Promise.all(scopes.map((scope) => GuardCatalog.#srvkitExports(sys, scope)))).flat();
|
|
2315
|
+
const frameworkGuards = GuardCatalog.frameworkGuards.map((name) => ({ name, specifier: "akanjs/signal" }));
|
|
2316
|
+
return new GuardCatalog([...exports.filter((entry) => entry.kind === "Guard"), ...frameworkGuards], exports.filter((entry) => entry.kind === "InternalArg"), reachedLibs);
|
|
2317
|
+
}
|
|
2318
|
+
get names() {
|
|
2319
|
+
return [...new Set(this.#guards.map((guard) => guard.name))];
|
|
2320
|
+
}
|
|
2321
|
+
resolve(name) {
|
|
2322
|
+
const matches = this.#guards.filter((guard) => guard.name === name);
|
|
2323
|
+
const specifiers = [...new Set(matches.map((guard) => guard.specifier))];
|
|
2324
|
+
return { specifier: specifiers[0] ?? null, ambiguous: specifiers.length > 1 ? specifiers : null };
|
|
2325
|
+
}
|
|
2326
|
+
actingUserOf(guards) {
|
|
2327
|
+
for (const guard of guards) {
|
|
2328
|
+
const acting = GuardCatalog.#actingArgOf.get(guard);
|
|
2329
|
+
const specifier = acting ? this.#internalArgs.find((entry) => entry.name === acting.argName)?.specifier : undefined;
|
|
2330
|
+
if (acting && specifier)
|
|
2331
|
+
return { ...acting, specifier };
|
|
2332
|
+
}
|
|
2333
|
+
return null;
|
|
2334
|
+
}
|
|
2335
|
+
static async#reachedLibs(sys) {
|
|
2336
|
+
const workspaceLibs = await sys.workspace.getLibs();
|
|
2337
|
+
const depsOf = async (type, name) => {
|
|
2338
|
+
const jsonPath = `${type}s/${name}/akan.${type}.json`;
|
|
2339
|
+
if (!await sys.workspace.exists(jsonPath))
|
|
2340
|
+
return null;
|
|
2341
|
+
const { libDeps } = await sys.workspace.readJson(jsonPath);
|
|
2342
|
+
return Array.isArray(libDeps) ? libDeps.filter((lib) => workspaceLibs.includes(lib)) : [];
|
|
2343
|
+
};
|
|
2344
|
+
const direct = await depsOf(sys.type, sys.name);
|
|
2345
|
+
if (!direct)
|
|
2346
|
+
return workspaceLibs.filter((lib) => sys.type !== "lib" || lib !== sys.name);
|
|
2347
|
+
const reached = new Set;
|
|
2348
|
+
const queue = [...direct];
|
|
2349
|
+
while (queue.length) {
|
|
2350
|
+
const lib = queue.shift();
|
|
2351
|
+
if (!lib || reached.has(lib) || sys.type === "lib" && lib === sys.name)
|
|
2352
|
+
continue;
|
|
2353
|
+
reached.add(lib);
|
|
2354
|
+
queue.push(...await depsOf("lib", lib) ?? []);
|
|
2355
|
+
}
|
|
2356
|
+
return [...reached];
|
|
2357
|
+
}
|
|
2358
|
+
static async#srvkitExports(sys, scope) {
|
|
2359
|
+
const dir = `${scope.type}s/${scope.name}/srvkit`;
|
|
2360
|
+
const files = (await sys.workspace.readdir(dir)).filter((file) => /\.tsx?$/.test(file) && !/\.(test|spec)\.tsx?$/.test(file) && file !== "index.ts");
|
|
2361
|
+
const specifier = `@${scope.type}s/${scope.name}/srvkit`;
|
|
2362
|
+
const contents = await Promise.all(files.map((file) => sys.workspace.readFile(`${dir}/${file}`)));
|
|
2363
|
+
return contents.flatMap((content) => [...content.matchAll(/export class ([A-Z][A-Za-z0-9_]*)\s+implements\s+([^{]+)\{/g)].flatMap((match) => {
|
|
2364
|
+
const implemented = (match[2] ?? "").split(",").map((name) => name.replace(/<.*$/s, "").trim());
|
|
2365
|
+
const kind = implemented.includes("Guard") ? "Guard" : implemented.includes("InternalArg") ? "InternalArg" : null;
|
|
2366
|
+
return kind && match[1] ? [{ kind, name: match[1], specifier }] : [];
|
|
2367
|
+
}));
|
|
2368
|
+
}
|
|
2369
|
+
}
|
|
2370
|
+
// pkgs/@akanjs/devkit/workflow/mutationScaffold.ts
|
|
2371
|
+
import { lowerlize as lowerlize4, modelNames } from "akanjs/common";
|
|
2372
|
+
|
|
2373
|
+
// pkgs/@akanjs/devkit/workflow/mutationSource.ts
|
|
2374
|
+
import { lowerlize as lowerlize3 } from "akanjs/common";
|
|
2375
|
+
class MutationSource {
|
|
2376
|
+
static #irregularParticiples = new Map([
|
|
2377
|
+
["admit", "admitted"],
|
|
2378
|
+
["bind", "bound"],
|
|
2379
|
+
["build", "built"],
|
|
2380
|
+
["choose", "chosen"],
|
|
2381
|
+
["commit", "committed"],
|
|
2382
|
+
["control", "controlled"],
|
|
2383
|
+
["cut", "cut"],
|
|
2384
|
+
["find", "found"],
|
|
2385
|
+
["freeze", "frozen"],
|
|
2386
|
+
["get", "got"],
|
|
2387
|
+
["give", "given"],
|
|
2388
|
+
["hide", "hidden"],
|
|
2389
|
+
["hold", "held"],
|
|
2390
|
+
["keep", "kept"],
|
|
2391
|
+
["lead", "led"],
|
|
2392
|
+
["leave", "left"],
|
|
2393
|
+
["lose", "lost"],
|
|
2394
|
+
["make", "made"],
|
|
2395
|
+
["omit", "omitted"],
|
|
2396
|
+
["pay", "paid"],
|
|
2397
|
+
["permit", "permitted"],
|
|
2398
|
+
["put", "put"],
|
|
2399
|
+
["read", "read"],
|
|
2400
|
+
["run", "run"],
|
|
2401
|
+
["sell", "sold"],
|
|
2402
|
+
["send", "sent"],
|
|
2403
|
+
["set", "set"],
|
|
2404
|
+
["show", "shown"],
|
|
2405
|
+
["shut", "shut"],
|
|
2406
|
+
["split", "split"],
|
|
2407
|
+
["submit", "submitted"],
|
|
2408
|
+
["take", "taken"],
|
|
2409
|
+
["transfer", "transferred"],
|
|
2410
|
+
["win", "won"],
|
|
2411
|
+
["write", "written"]
|
|
2412
|
+
]);
|
|
2413
|
+
spec;
|
|
2414
|
+
modelClassName;
|
|
2415
|
+
model;
|
|
2416
|
+
idParam;
|
|
2417
|
+
chainMethod;
|
|
2418
|
+
constructor(spec) {
|
|
2419
|
+
this.spec = spec;
|
|
2420
|
+
this.modelClassName = moduleComponentName(spec.module);
|
|
2421
|
+
this.model = lowerlize3(this.modelClassName);
|
|
2422
|
+
this.idParam = `${this.model}Id`;
|
|
2423
|
+
this.chainMethod = MutationSource.chainMethodOf(spec.mutation, this.modelClassName);
|
|
2424
|
+
}
|
|
2425
|
+
static chainMethodOf(mutation, modelClassName) {
|
|
2426
|
+
const dropped = mutation.replace(modelClassName, "");
|
|
2427
|
+
return dropped && dropped !== mutation ? lowerlize3(dropped) : mutation;
|
|
2428
|
+
}
|
|
2429
|
+
static participleOf(verb) {
|
|
2430
|
+
const irregular = MutationSource.#irregularParticiples.get(verb);
|
|
2431
|
+
if (irregular)
|
|
2432
|
+
return irregular;
|
|
2433
|
+
if (verb.endsWith("e"))
|
|
2434
|
+
return `${verb}d`;
|
|
2435
|
+
if (/[^aeiou]y$/.test(verb))
|
|
2436
|
+
return `${verb.slice(0, -1)}ied`;
|
|
2437
|
+
if (/^[^aeiou]*[aeiou][^aeiouwxy]$/.test(verb))
|
|
2438
|
+
return `${verb}${verb.at(-1)}ed`;
|
|
2439
|
+
return `${verb}ed`;
|
|
2440
|
+
}
|
|
2441
|
+
get isPublic() {
|
|
2442
|
+
return this.spec.guards.includes("Public");
|
|
2443
|
+
}
|
|
2444
|
+
get #verb() {
|
|
2445
|
+
return this.chainMethod.replace(/[A-Z].*$/s, "");
|
|
2446
|
+
}
|
|
2447
|
+
get #noun() {
|
|
2448
|
+
return titleize(this.model).toLowerCase();
|
|
2449
|
+
}
|
|
2450
|
+
get chainMethodBlock() {
|
|
2451
|
+
return [
|
|
2452
|
+
` // any \u2192 ${MutationSource.participleOf(this.#verb)}.`,
|
|
2453
|
+
` ${this.chainMethod}() {`,
|
|
2454
|
+
" return this;",
|
|
2455
|
+
" }"
|
|
2456
|
+
].join(`
|
|
2457
|
+
`);
|
|
2458
|
+
}
|
|
2459
|
+
get serviceMethod() {
|
|
2460
|
+
return this.chainMethod;
|
|
2461
|
+
}
|
|
2462
|
+
get serviceMethodBlock() {
|
|
2463
|
+
const { acting } = this.spec;
|
|
2464
|
+
const params = [`${this.idParam}: string`, ...acting ? [`${acting.serviceParam}: string`] : []];
|
|
2465
|
+
const load = `const ${this.model} = await this.get${this.modelClassName}(${this.idParam});`;
|
|
2466
|
+
const owned = acting ? [
|
|
2467
|
+
`// TODO: ${this.spec.guards.join(" and ")} admits any signed-in caller; refuse a ${acting.serviceParam} that may not ${this.#verb} this ${this.#noun}.`
|
|
2468
|
+
] : [];
|
|
2469
|
+
const chained = `${this.model}.${this.chainMethod}().save()`;
|
|
2470
|
+
const head = ` async ${this.serviceMethod}(${params.join(", ")}) {`;
|
|
2471
|
+
if (!this.spec.withCalls.length && !this.spec.afterCalls.length)
|
|
2472
|
+
return [head, ` ${load}`, ...owned.map((line) => ` ${line}`), ` return await ${chained};`, " }"].join(`
|
|
2473
|
+
`);
|
|
2474
|
+
return [
|
|
2475
|
+
head,
|
|
2476
|
+
" return await this.transaction(async () => {",
|
|
2477
|
+
` ${load}`,
|
|
2478
|
+
...owned.map((line) => ` ${line}`),
|
|
2479
|
+
` await ${chained};`,
|
|
2480
|
+
...this.spec.withCalls.map((call) => ` await ${MutationSource.#callOf(call)};`),
|
|
2481
|
+
...this.spec.afterCalls.map((call) => ` await this.afterCommit(() => ${MutationSource.#callOf(call)});`),
|
|
2482
|
+
` return ${this.model};`,
|
|
2483
|
+
" });",
|
|
2484
|
+
" }"
|
|
2485
|
+
].join(`
|
|
2486
|
+
`);
|
|
2487
|
+
}
|
|
2488
|
+
get signalEntry() {
|
|
2489
|
+
const options = this.isPublic ? `{ guards: [${this.spec.guards.join(", ")}], rateLimit: { calls: 20 } }` : `{ guards: [${this.spec.guards.join(", ")}] }`;
|
|
2490
|
+
const { acting } = this.spec;
|
|
2491
|
+
const execParams = [this.idParam, ...acting ? [acting.param] : []];
|
|
2492
|
+
const serviceArgs = [this.idParam, ...acting ? [acting.value] : []];
|
|
2493
|
+
return [
|
|
2494
|
+
`${this.spec.mutation}: mutation(cnst.${this.modelClassName}, ${options})`,
|
|
2495
|
+
` .param("${this.idParam}", ID)`,
|
|
2496
|
+
...acting ? [` .with(${acting.argName})`] : [],
|
|
2497
|
+
` .exec(async function (${execParams.join(", ")}) {`,
|
|
2498
|
+
` return await this.${this.model}Service.${this.serviceMethod}(${serviceArgs.join(", ")});`,
|
|
2499
|
+
" }),"
|
|
2500
|
+
].join(`
|
|
2501
|
+
`);
|
|
2502
|
+
}
|
|
2503
|
+
get storeActionBlock() {
|
|
2504
|
+
return [
|
|
2505
|
+
` async ${this.spec.mutation}(${this.idParam}: string) {`,
|
|
2506
|
+
` this.set${this.modelClassName}(await fetch.${this.spec.mutation}(${this.idParam}));`,
|
|
2507
|
+
" }"
|
|
2508
|
+
].join(`
|
|
2509
|
+
`);
|
|
2510
|
+
}
|
|
2511
|
+
dictionaryEntryOf(modelKo) {
|
|
2512
|
+
const label = bilingualLabelForField(this.spec.mutation);
|
|
2513
|
+
const modelLabel = { ...bilingualLabelForField(this.model), ...modelKo ? { ko: modelKo } : {} };
|
|
2514
|
+
const pair = (en, ko) => `[${JSON.stringify(en)}, ${JSON.stringify(ko)}]`;
|
|
2515
|
+
const idPair = pair(`${modelLabel.en} ID`, `${modelLabel.ko} ID`);
|
|
2516
|
+
return [
|
|
2517
|
+
`${this.spec.mutation}: fn(${pair(label.en, label.ko)})`,
|
|
2518
|
+
` .desc(${pair(`API to ${label.en.toLowerCase()}`, `${label.ko} API`)})`,
|
|
2519
|
+
" .arg((t) => ({",
|
|
2520
|
+
` ${this.idParam}: t(${idPair}).desc(${idPair}),`,
|
|
2521
|
+
" })),"
|
|
2522
|
+
].join(`
|
|
2523
|
+
`);
|
|
2524
|
+
}
|
|
2525
|
+
get testTitles() {
|
|
2526
|
+
const guards = this.spec.guards.join(" and ");
|
|
2527
|
+
const participle = MutationSource.participleOf(this.#verb);
|
|
2528
|
+
return [
|
|
2529
|
+
`${this.spec.mutation} leaves the ${this.#noun} ${participle} for a caller ${guards} admits`,
|
|
2530
|
+
...this.spec.guards.every((guard) => guard === "Public") ? [] : [`${this.spec.mutation} refuses a caller ${guards} turns away`],
|
|
2531
|
+
...this.spec.acting ? [`${this.spec.mutation} refuses a signed-in caller who may not ${this.#verb} the ${this.#noun}`] : []
|
|
2532
|
+
];
|
|
2533
|
+
}
|
|
2534
|
+
testCaseLines(itName, indent) {
|
|
2535
|
+
return this.testTitles.map((title) => `${indent}${itName}.todo(${JSON.stringify(title)});`);
|
|
2536
|
+
}
|
|
2537
|
+
get testFile() {
|
|
2538
|
+
return [
|
|
2539
|
+
'import { describe, it } from "bun:test";',
|
|
2540
|
+
"",
|
|
2541
|
+
`describe(${JSON.stringify(`${this.modelClassName} Signal`)}, () => {`,
|
|
2542
|
+
...this.testCaseLines("it", " "),
|
|
2543
|
+
"});",
|
|
2544
|
+
""
|
|
2545
|
+
].join(`
|
|
2546
|
+
`);
|
|
2547
|
+
}
|
|
2548
|
+
static #callOf(call) {
|
|
2549
|
+
const target = call.field ? `this.${call.field}` : "this";
|
|
2550
|
+
return `${target}.${call.method}(${call.args.join(", ")})`;
|
|
2551
|
+
}
|
|
2552
|
+
}
|
|
2553
|
+
|
|
2554
|
+
// pkgs/@akanjs/devkit/workflow/mutationScaffold.ts
|
|
2555
|
+
class MutationScaffold {
|
|
2556
|
+
static #documentMethods = new Set(["isModified", "refresh", "remove", "save", "set", "toJSON", "toObject"]);
|
|
2557
|
+
static #serviceMethods = new Set(["afterCommit", "logger", "onDestroy", "onInit", "transaction"]);
|
|
2558
|
+
static #callPattern = /^_?([a-z][A-Za-z0-9]*)\.([A-Za-z_$][\w$]*)$/;
|
|
2559
|
+
#sys;
|
|
2560
|
+
#catalog;
|
|
2561
|
+
#strict;
|
|
2562
|
+
#diagnostics = [];
|
|
2563
|
+
constructor(sys, catalog, { strict }) {
|
|
2564
|
+
this.#sys = sys;
|
|
2565
|
+
this.#catalog = catalog;
|
|
2566
|
+
this.#strict = strict;
|
|
2567
|
+
}
|
|
2568
|
+
static reservedNamesOf(modelClassName) {
|
|
2569
|
+
const names = modelNames(lowerlize4(modelClassName));
|
|
2570
|
+
return new Set([
|
|
2571
|
+
names.model,
|
|
2572
|
+
names.lightModel,
|
|
2573
|
+
names.createModel,
|
|
2574
|
+
names.updateModel,
|
|
2575
|
+
names.removeModel,
|
|
2576
|
+
names.viewModel,
|
|
2577
|
+
names.editModel,
|
|
2578
|
+
names.mergeModel,
|
|
2579
|
+
names.getModel,
|
|
2580
|
+
names.loadModel,
|
|
2581
|
+
names.setModel,
|
|
2582
|
+
names.resetModel,
|
|
2583
|
+
names.newModel,
|
|
2584
|
+
names.submitModel,
|
|
2585
|
+
names.invalidateModel,
|
|
2586
|
+
names.createModelInForm,
|
|
2587
|
+
names.updateModelInForm,
|
|
2588
|
+
names.loadModelMany,
|
|
2589
|
+
names.getModelView,
|
|
2590
|
+
names.getModelEdit,
|
|
2591
|
+
names.addModelFiles,
|
|
2592
|
+
names.checkModelSubmitable,
|
|
2593
|
+
names.writeOnModel,
|
|
2594
|
+
names.loadModelFormDraft,
|
|
2595
|
+
names.restoreModelFormDraft,
|
|
2596
|
+
names.discardModelFormDraft
|
|
2597
|
+
]);
|
|
2598
|
+
}
|
|
2599
|
+
static generates(modelClassName, name) {
|
|
2600
|
+
return MutationScaffold.reservedNamesOf(modelClassName).has(name) || new RegExp(`^(init${modelClassName}|get${modelClassName}Init|(set|add|sub|upload)\\w+On${modelClassName}$)`).test(name);
|
|
2601
|
+
}
|
|
2602
|
+
static inputDiagnostics(input) {
|
|
2603
|
+
const diagnostics = [];
|
|
2604
|
+
const error = (code, inputName, message) => diagnostics.push({ severity: "error", code, input: inputName, message });
|
|
2605
|
+
const { module, mutation } = input;
|
|
2606
|
+
if (mutation && !/^[a-z][A-Za-z0-9]*$/.test(mutation))
|
|
2607
|
+
error("add-mutation-name-invalid", "mutation", `Mutation name "${mutation}" must be a camelCase identifier.`);
|
|
2608
|
+
if (module && mutation) {
|
|
2609
|
+
const modelClassName = moduleComponentName(module);
|
|
2610
|
+
if (MutationScaffold.generates(modelClassName, mutation))
|
|
2611
|
+
error("add-mutation-name-reserved", "mutation", `"${mutation}" collides with a name Akan generates for ${modelClassName} (CRUD endpoints, store actions, form setters). Name the act, e.g. archive${modelClassName}.`);
|
|
2612
|
+
const chainMethod = MutationSource.chainMethodOf(mutation, modelClassName);
|
|
2613
|
+
if (MutationScaffold.#documentMethods.has(chainMethod))
|
|
2614
|
+
error("add-mutation-name-reserved", "mutation", `"${mutation}" drops to the document chain method ${chainMethod}(), which every document already has.`);
|
|
2615
|
+
else if (MutationScaffold.#serviceMethods.has(chainMethod))
|
|
2616
|
+
error("add-mutation-name-reserved", "mutation", `"${mutation}" drops to the service method ${chainMethod}(), which every service already has.`);
|
|
2617
|
+
}
|
|
2618
|
+
const guards = input.guards ?? [];
|
|
2619
|
+
if (!guards.length)
|
|
2620
|
+
error("add-mutation-guard-missing", "guard", "Name the guard(s) that admit a caller (guard=Admin, guard=Every,Person); add-mutation has no default guard.");
|
|
2621
|
+
for (const guard of guards) {
|
|
2622
|
+
if (guard === "None")
|
|
2623
|
+
error("add-mutation-guard-none", "guard", "None answers no caller, so the endpoint would ship dead; name the guard that admits the intended caller.");
|
|
2624
|
+
else if (!/^[A-Z][A-Za-z0-9]*$/.test(guard))
|
|
2625
|
+
error("add-mutation-guard-invalid", "guard", `Guard "${guard}" must be a guard class name.`);
|
|
2626
|
+
}
|
|
2627
|
+
for (const [inputName, calls] of [
|
|
2628
|
+
["with", input.withCalls],
|
|
2629
|
+
["after", input.afterCalls]
|
|
2630
|
+
]) {
|
|
2631
|
+
for (const call of calls ?? [])
|
|
2632
|
+
if (!MutationScaffold.#callPattern.test(call))
|
|
2633
|
+
error("add-mutation-call-invalid", inputName, `"${call}" must name a service method as <serviceRef>.<method>, e.g. courtPc.pushPcCommand.`);
|
|
2634
|
+
}
|
|
2635
|
+
return diagnostics;
|
|
2636
|
+
}
|
|
2637
|
+
static async build(sys, input, { strict = true } = {}) {
|
|
2638
|
+
return await new MutationScaffold(sys, await GuardCatalog.load(sys), { strict }).#build(input);
|
|
2639
|
+
}
|
|
2640
|
+
async#build(input) {
|
|
2641
|
+
const files = [];
|
|
2642
|
+
const recommendations = [];
|
|
2643
|
+
this.#diagnostics.push(...MutationScaffold.inputDiagnostics(input));
|
|
2644
|
+
const { module, mutation } = input;
|
|
2645
|
+
const guards = [...new Set(input.guards ?? [])];
|
|
2646
|
+
const guardSpecifiers = this.#resolveGuards(guards);
|
|
2647
|
+
if (this.#hasGuardError())
|
|
2648
|
+
recommendations.push({
|
|
2649
|
+
code: "add-mutation-guard-choices",
|
|
2650
|
+
kind: "input-guidance",
|
|
2651
|
+
confidence: "high",
|
|
2652
|
+
message: `Guards this target reaches: ${this.#catalog.names.join(", ") || "none"}.`,
|
|
2653
|
+
action: "Re-plan with guard set to one or more of these names."
|
|
2654
|
+
});
|
|
2655
|
+
if (!module || !mutation || this.#hasError())
|
|
2656
|
+
return this.#result(files, recommendations);
|
|
2657
|
+
const paths = moduleSourcePaths(module);
|
|
2658
|
+
const sourcePaths = [paths.document, paths.service, paths.signal, paths.store, paths.dictionary];
|
|
2659
|
+
const present = await Promise.all(sourcePaths.map((path) => this.#sys.exists(path)));
|
|
2660
|
+
const missing = sourcePaths.filter((_, idx) => !present[idx]);
|
|
2661
|
+
if (missing.length) {
|
|
2662
|
+
this.#report("add-mutation-module-missing", `Module ${module} lacks ${missing.join(", ")}; add-mutation writes into an existing database module (create-module first).`, { input: "module" });
|
|
2663
|
+
return this.#result(files, recommendations);
|
|
2664
|
+
}
|
|
2665
|
+
const acting = this.#catalog.actingUserOf(guards);
|
|
2666
|
+
if (acting)
|
|
2667
|
+
recommendations.push({
|
|
2668
|
+
code: "add-mutation-ownership",
|
|
2669
|
+
kind: "manual-action",
|
|
2670
|
+
confidence: "high",
|
|
2671
|
+
message: `${guards.join(" and ")} admits any signed-in caller, so the service receives ${acting.serviceParam} and a TODO where it must refuse a caller who may not act on this ${module}.`,
|
|
2672
|
+
action: `Check ${acting.serviceParam} against the ${module} before the chain, or guard the mutation with a Can<Verb><Model> resource guard.`
|
|
2673
|
+
});
|
|
2674
|
+
const source = new MutationSource({
|
|
2675
|
+
module,
|
|
2676
|
+
mutation,
|
|
2677
|
+
guards,
|
|
2678
|
+
acting,
|
|
2679
|
+
withCalls: [],
|
|
2680
|
+
afterCalls: []
|
|
2681
|
+
});
|
|
2682
|
+
const [document, service, signal, store, dictionary] = await Promise.all(sourcePaths.map((path) => this.#sys.readFile(path)));
|
|
2683
|
+
await this.#checkNameFree(source, { service, signal, store, dictionary });
|
|
2684
|
+
const withCalls = await this.#resolveCalls(source, input.withCalls ?? [], "with", acting);
|
|
2685
|
+
const afterCalls = await this.#resolveCalls(source, input.afterCalls ?? [], "after", acting);
|
|
2686
|
+
if (this.#hasError())
|
|
2687
|
+
return this.#result(files, recommendations);
|
|
2688
|
+
const shaped = new MutationSource({ module, mutation, guards, acting, withCalls, afterCalls });
|
|
2689
|
+
const testPath = `lib/${module}/${module}.signal.test.ts`;
|
|
2690
|
+
const testExists = await this.#sys.exists(testPath);
|
|
2691
|
+
const edits = [
|
|
2692
|
+
[paths.document, this.#editDocument(document, shaped), "Document chain method was added.", "modify"],
|
|
2693
|
+
[
|
|
2694
|
+
paths.service,
|
|
2695
|
+
this.#editService(service, shaped, [...withCalls, ...afterCalls]),
|
|
2696
|
+
"Service mutation was added.",
|
|
2697
|
+
"modify"
|
|
2698
|
+
],
|
|
2699
|
+
[paths.signal, this.#editSignal(signal, shaped, guardSpecifiers, acting), "Signal mutation was added.", "modify"],
|
|
2700
|
+
[paths.store, this.#editStore(store, shaped), "Store action was added.", "modify"],
|
|
2701
|
+
[paths.dictionary, this.#editDictionary(dictionary, shaped), "Dictionary endpoint entry was added.", "modify"],
|
|
2702
|
+
[
|
|
2703
|
+
testPath,
|
|
2704
|
+
testExists ? appendTopLevelTestCases(await this.#sys.readFile(testPath), `${shaped.modelClassName} Signal`, (itName, indent) => shaped.testCaseLines(itName, indent)) : shaped.testFile,
|
|
2705
|
+
"Signal test placeholders were added.",
|
|
2706
|
+
testExists ? "modify" : "create"
|
|
2707
|
+
]
|
|
2708
|
+
];
|
|
2709
|
+
for (const [path, content, reason, action] of edits) {
|
|
2710
|
+
if (content === null)
|
|
2711
|
+
continue;
|
|
2712
|
+
if (hasSourceParseErrors(content, path))
|
|
2713
|
+
this.#report("add-mutation-post-edit-parse-failed", `Edited ${path} did not parse; refusing to write source.`, {
|
|
2714
|
+
severity: "error"
|
|
2715
|
+
});
|
|
2716
|
+
files.push({ path, content, reason, action });
|
|
2717
|
+
}
|
|
2718
|
+
return this.#result(files, recommendations);
|
|
2719
|
+
}
|
|
2720
|
+
#result(files, recommendations) {
|
|
2721
|
+
const diagnostics = this.#diagnostics;
|
|
2722
|
+
return { diagnostics, recommendations, files: this.#hasError() ? [] : files };
|
|
2723
|
+
}
|
|
2724
|
+
#hasError() {
|
|
2725
|
+
return this.#diagnostics.some((diagnostic) => diagnostic.severity === "error");
|
|
2726
|
+
}
|
|
2727
|
+
#hasGuardError() {
|
|
2728
|
+
return this.#diagnostics.some((diagnostic) => diagnostic.code.startsWith("add-mutation-guard"));
|
|
2729
|
+
}
|
|
2730
|
+
#report(code, message, { input, severity } = {}) {
|
|
2731
|
+
this.#diagnostics.push({
|
|
2732
|
+
severity: severity ?? (this.#strict ? "error" : "warning"),
|
|
2733
|
+
code,
|
|
2734
|
+
message,
|
|
2735
|
+
input,
|
|
2736
|
+
failureScope: "source-change"
|
|
2737
|
+
});
|
|
2738
|
+
}
|
|
2739
|
+
#resolveGuards(guards) {
|
|
2740
|
+
const specifiers = new Map;
|
|
2741
|
+
for (const guard of guards) {
|
|
2742
|
+
if (guard === "None")
|
|
2743
|
+
continue;
|
|
2744
|
+
const { specifier, ambiguous } = this.#catalog.resolve(guard);
|
|
2745
|
+
if (ambiguous)
|
|
2746
|
+
this.#report("add-mutation-guard-ambiguous", `Guard "${guard}" is exported by ${ambiguous.join(" and ")}.`, {
|
|
2747
|
+
input: "guard",
|
|
2748
|
+
severity: "error"
|
|
2749
|
+
});
|
|
2750
|
+
else if (!specifier)
|
|
2751
|
+
this.#report("add-mutation-guard-unknown", `Guard "${guard}" is not exported by ${this.#sys.type}s/${this.#sys.name}/srvkit, the srvkit of a lib it reaches (${this.#catalog.reachedLibs.join(", ") || "none"}), or akanjs/signal.`, { input: "guard", severity: "error" });
|
|
2752
|
+
else
|
|
2753
|
+
specifiers.set(guard, specifier);
|
|
2754
|
+
}
|
|
2755
|
+
return specifiers;
|
|
2756
|
+
}
|
|
2757
|
+
async#checkNameFree(source, files) {
|
|
2758
|
+
const { mutation } = source.spec;
|
|
2759
|
+
const { modelClassName } = source;
|
|
2760
|
+
const taken = [
|
|
2761
|
+
hasClassMethod(files.service, `${modelClassName}Service`, source.serviceMethod) && `${modelClassName}Service.${source.serviceMethod}()`,
|
|
2762
|
+
["Internal", "Slice", "Endpoint"].some((kind) => hasSignalFactoryEntry(files.signal, `${modelClassName}${kind}`, mutation)) && `${source.spec.module}.signal.ts`,
|
|
2763
|
+
hasClassMethod(files.store, `${modelClassName}Store`, mutation) && `${modelClassName}Store`,
|
|
2764
|
+
hasDictionaryEndpointEntry(files.dictionary, modelClassName, mutation) && `${source.spec.module}.dictionary.ts`,
|
|
2765
|
+
...await this.#signalsDeclaring(mutation, source.spec.module)
|
|
2766
|
+
].filter((place) => !!place);
|
|
2767
|
+
if (taken.length)
|
|
2768
|
+
this.#report("add-mutation-name-exists", `"${mutation}" already exists in ${taken.join(", ")}.`, {
|
|
2769
|
+
input: "mutation",
|
|
2770
|
+
severity: "error"
|
|
2771
|
+
});
|
|
2772
|
+
}
|
|
2773
|
+
async#signalsDeclaring(mutation, ownModule) {
|
|
2774
|
+
const pattern = new RegExp(`^\\s*${mutation}:\\s*(mutation|query|pubsub|message)\\(`, "m");
|
|
2775
|
+
const roots = [`${this.#sys.type}s/${this.#sys.name}`, ...this.#catalog.reachedLibs.map((lib) => `libs/${lib}`)];
|
|
2776
|
+
const hits = await Promise.all(roots.map(async (root) => {
|
|
2777
|
+
if (!await this.#sys.workspace.exists(`${root}/lib`))
|
|
2778
|
+
return [];
|
|
2779
|
+
const folders = (await this.#sys.workspace.readdir(`${root}/lib`)).filter((folder) => !folder.includes(".") && !folder.startsWith("__") && !(root === roots[0] && folder === ownModule));
|
|
2780
|
+
return await Promise.all(folders.map(async (folder) => {
|
|
2781
|
+
const name = folder.replace(/^_+/, "");
|
|
2782
|
+
const base = `${root}/lib/${folder}/${name}`;
|
|
2783
|
+
if (await this.#sys.workspace.exists(`${base}.document.ts`) && MutationScaffold.generates(moduleComponentName(name), mutation))
|
|
2784
|
+
return `${root}/lib/${folder} (generated for ${moduleComponentName(name)})`;
|
|
2785
|
+
if (!await this.#sys.workspace.exists(`${base}.signal.ts`))
|
|
2786
|
+
return null;
|
|
2787
|
+
return pattern.test(await this.#sys.workspace.readFile(`${base}.signal.ts`)) ? `${base}.signal.ts` : null;
|
|
2788
|
+
}));
|
|
2789
|
+
}));
|
|
2790
|
+
return hits.flat().filter((hit) => !!hit);
|
|
2791
|
+
}
|
|
2792
|
+
async#resolveCalls(source, calls, inputName, acting) {
|
|
2793
|
+
const resolved = [];
|
|
2794
|
+
for (const call of calls) {
|
|
2795
|
+
const [rawRef = "", method = ""] = call.split(".");
|
|
2796
|
+
const ref = rawRef.replace(/^_+/, "");
|
|
2797
|
+
const isOwn = ref === source.model;
|
|
2798
|
+
const service = await this.#serviceSourceOf(ref, isOwn);
|
|
2799
|
+
if (!service) {
|
|
2800
|
+
this.#report("add-mutation-call-service-missing", `${inputName}: no ${moduleComponentName(ref)}Service in ${this.#sys.name} or the libs it reaches.`, { input: inputName });
|
|
2801
|
+
continue;
|
|
2802
|
+
}
|
|
2803
|
+
const params = this.#parametersOf(service, ref, method);
|
|
2804
|
+
if (!params) {
|
|
2805
|
+
this.#report("add-mutation-call-method-missing", `${inputName}: ${service.className} has no ${method}().`, {
|
|
2806
|
+
input: inputName
|
|
2807
|
+
});
|
|
2808
|
+
continue;
|
|
2809
|
+
}
|
|
2810
|
+
const scope = new Map([
|
|
2811
|
+
[source.idParam, `${source.model}.id`],
|
|
2812
|
+
[source.model, source.model],
|
|
2813
|
+
...isOwn ? [["id", `${source.model}.id`]] : [],
|
|
2814
|
+
...acting ? [[acting.serviceParam, acting.serviceParam]] : []
|
|
2815
|
+
]);
|
|
2816
|
+
const args = [];
|
|
2817
|
+
for (const param of params) {
|
|
2818
|
+
const value = param.name ? scope.get(param.name) : undefined;
|
|
2819
|
+
if (value) {
|
|
2820
|
+
args.push(value);
|
|
2821
|
+
continue;
|
|
2822
|
+
}
|
|
2823
|
+
if (!param.optional)
|
|
2824
|
+
this.#report("add-mutation-call-args-unresolved", `${inputName}: ${service.className}.${method}() takes "${param.name ?? "?"}", which add-mutation cannot supply. Name a method taking the ${source.model}, its id or the acting user, or call this one by hand after apply.`, { input: inputName, severity: "error" });
|
|
2825
|
+
break;
|
|
2826
|
+
}
|
|
2827
|
+
const field = isOwn ? null : `${ref}Service`;
|
|
2828
|
+
resolved.push({
|
|
2829
|
+
ref,
|
|
2830
|
+
method,
|
|
2831
|
+
field,
|
|
2832
|
+
args,
|
|
2833
|
+
injection: field ? { field, typeRef: service.typeRef } : null
|
|
2834
|
+
});
|
|
2835
|
+
}
|
|
2836
|
+
return resolved;
|
|
2837
|
+
}
|
|
2838
|
+
async#serviceSourceOf(ref, isOwn) {
|
|
2839
|
+
const className = `${moduleComponentName(ref)}Service`;
|
|
2840
|
+
const scopes = [
|
|
2841
|
+
{ root: `${this.#sys.type}s/${this.#sys.name}`, typeRef: `srv.${className}` },
|
|
2842
|
+
...isOwn ? [] : this.#catalog.reachedLibs.map((lib) => ({ root: `libs/${lib}`, typeRef: `srv.${lib}.${className}` }))
|
|
2843
|
+
];
|
|
2844
|
+
for (const { root, typeRef } of scopes) {
|
|
2845
|
+
for (const folder of [ref, `_${ref}`]) {
|
|
2846
|
+
const path = `${root}/lib/${folder}/${ref}.service.ts`;
|
|
2847
|
+
if (await this.#sys.workspace.exists(path))
|
|
2848
|
+
return { className, typeRef, content: await this.#sys.workspace.readFile(path) };
|
|
2849
|
+
}
|
|
2850
|
+
}
|
|
2851
|
+
return null;
|
|
2852
|
+
}
|
|
2853
|
+
#parametersOf(service, ref, method) {
|
|
2854
|
+
const declared = classMethodParameters(service.content, service.className, method);
|
|
2855
|
+
if (declared)
|
|
2856
|
+
return declared;
|
|
2857
|
+
const names = modelNames(lowerlize4(moduleComponentName(ref)));
|
|
2858
|
+
const generated = {
|
|
2859
|
+
[names.getModel]: [{ name: "id", optional: false }],
|
|
2860
|
+
[names.loadModel]: [{ name: "id", optional: true }],
|
|
2861
|
+
[names.loadModelMany]: [{ name: "ids", optional: false }],
|
|
2862
|
+
[names.createModel]: [{ name: "data", optional: false }],
|
|
2863
|
+
[names.updateModel]: [
|
|
2864
|
+
{ name: "id", optional: false },
|
|
2865
|
+
{ name: "data", optional: false }
|
|
2866
|
+
],
|
|
2867
|
+
[names.removeModel]: [{ name: "id", optional: false }]
|
|
2868
|
+
};
|
|
2869
|
+
return generated[method] ?? null;
|
|
2870
|
+
}
|
|
2871
|
+
#editDocument(content, source) {
|
|
2872
|
+
if (hasClassMethod(content, source.modelClassName, source.chainMethod)) {
|
|
2873
|
+
this.#report("add-mutation-chain-method-reused", `${source.modelClassName}.${source.chainMethod}() already exists; the service chains it as is.`, { severity: "warning" });
|
|
2874
|
+
return null;
|
|
2875
|
+
}
|
|
2876
|
+
return this.#required(insertClassMethod(content, source.modelClassName, source.chainMethodBlock), `class ${source.modelClassName} in the document`);
|
|
2877
|
+
}
|
|
2878
|
+
#editService(content, source, calls) {
|
|
2879
|
+
const className = `${source.modelClassName}Service`;
|
|
2880
|
+
let next = content;
|
|
2881
|
+
for (const { injection } of calls) {
|
|
2882
|
+
if (!next || !injection || hasSignalFactoryEntry(next, className, injection.field))
|
|
2883
|
+
continue;
|
|
2884
|
+
next = insertSignalFactoryEntry(next, className, injection.field, `${injection.field}: service<${injection.typeRef}>(),`, {
|
|
2885
|
+
mode: "destructure",
|
|
2886
|
+
name: "service"
|
|
2887
|
+
});
|
|
2888
|
+
if (next && !/\* as srv from "\.\.\/srv";/.test(next))
|
|
2889
|
+
next = ensureImportDeclaration(next, "../srv", "type * as srv");
|
|
2890
|
+
}
|
|
2891
|
+
next = next && insertClassMethod(next, className, source.serviceMethodBlock);
|
|
2892
|
+
return this.#required(next, `${className} and its serve() factory`);
|
|
2893
|
+
}
|
|
2894
|
+
#editSignal(content, source, guardSpecifiers, acting) {
|
|
2895
|
+
let next = insertSignalFactoryEntry(content, `${source.modelClassName}Endpoint`, source.spec.mutation, source.signalEntry, { mode: "destructure", name: "mutation" });
|
|
2896
|
+
if (!next)
|
|
2897
|
+
return this.#required(next, `${source.modelClassName}Endpoint and its endpoint() factory`);
|
|
2898
|
+
next = ensureNamedImport(next, "akanjs/base", "ID");
|
|
2899
|
+
if (!/\* as cnst from "\.\.\/cnst";/.test(next))
|
|
2900
|
+
next = ensureImportDeclaration(next, "../cnst", "* as cnst");
|
|
2901
|
+
for (const [guard, specifier] of guardSpecifiers)
|
|
2902
|
+
next = ensureNamedImport(next, specifier, guard);
|
|
2903
|
+
if (acting)
|
|
2904
|
+
next = ensureNamedImport(next, acting.specifier, acting.argName);
|
|
2905
|
+
return next;
|
|
2906
|
+
}
|
|
2907
|
+
#editStore(content, source) {
|
|
2908
|
+
const next = insertClassMethod(content, `${source.modelClassName}Store`, source.storeActionBlock);
|
|
2909
|
+
return this.#required(next && ensureNamedImport(next, "../useClient", "fetch"), `${source.modelClassName}Store`);
|
|
2910
|
+
}
|
|
2911
|
+
#editDictionary(content, source) {
|
|
2912
|
+
return this.#required(insertDictionaryEndpointEntry(content, source.modelClassName, source.spec.mutation, source.dictionaryEntryOf(MutationScaffold.#modelKoOf(content))), `.endpoint<${source.modelClassName}Endpoint>() in the dictionary`);
|
|
2913
|
+
}
|
|
2914
|
+
static #modelKoOf(dictionary) {
|
|
2915
|
+
return dictionary.match(/\.of\(\s*\(t\)\s*=>\s*t\(\s*\[\s*"[^"]*"\s*,\s*"([^"]+)"\s*\]/)?.[1];
|
|
2916
|
+
}
|
|
2917
|
+
#required(content, shape) {
|
|
2918
|
+
if (!content)
|
|
2919
|
+
this.#report("add-mutation-shape-unsupported", `Could not find ${shape}; refusing to write source.`, {
|
|
2920
|
+
severity: "error"
|
|
2921
|
+
});
|
|
2922
|
+
return content;
|
|
2923
|
+
}
|
|
2924
|
+
}
|
|
2087
2925
|
// pkgs/@akanjs/devkit/workflow/plan.ts
|
|
2088
|
-
import { capitalize as
|
|
2926
|
+
import { capitalize as capitalize4 } from "akanjs/common";
|
|
2089
2927
|
var surfaceModes = new Set(["infer", "include", "skip"]);
|
|
2928
|
+
var sysNamePattern = /^[a-z0-9][a-zA-Z0-9_-]*$/;
|
|
2929
|
+
var identifierPattern = /^_{0,2}[a-zA-Z][a-zA-Z0-9_-]*$/;
|
|
2930
|
+
var nameInputPatterns = {
|
|
2931
|
+
app: sysNamePattern,
|
|
2932
|
+
module: identifierPattern,
|
|
2933
|
+
scalar: identifierPattern,
|
|
2934
|
+
field: identifierPattern,
|
|
2935
|
+
slice: identifierPattern,
|
|
2936
|
+
mutation: identifierPattern,
|
|
2937
|
+
interaction: identifierPattern
|
|
2938
|
+
};
|
|
2939
|
+
var isWorkflowSysName = (value) => typeof value === "string" && sysNamePattern.test(value);
|
|
2940
|
+
var isWorkflowModuleName = (value) => typeof value === "string" && identifierPattern.test(value);
|
|
2090
2941
|
var parseStringList = (value) => {
|
|
2091
2942
|
if (Array.isArray(value)) {
|
|
2092
2943
|
const values = value.filter((item) => typeof item === "string" && item.trim().length > 0);
|
|
@@ -2228,7 +3079,7 @@ var createAddFieldRecommendations = (inputs) => {
|
|
|
2228
3079
|
kind: "placement",
|
|
2229
3080
|
target: paths.constant,
|
|
2230
3081
|
confidence: "high",
|
|
2231
|
-
message: `Insert ${field}: field(${normalizedType}) in ${
|
|
3082
|
+
message: `Insert ${field}: field(${normalizedType}) in ${capitalize4(module)}Input.`
|
|
2232
3083
|
},
|
|
2233
3084
|
{
|
|
2234
3085
|
code: "add-field-placement-dictionary",
|
|
@@ -2260,12 +3111,12 @@ var createAddFieldRecommendations = (inputs) => {
|
|
|
2260
3111
|
kind: "placement",
|
|
2261
3112
|
target: paths.constant,
|
|
2262
3113
|
confidence: "high",
|
|
2263
|
-
message: `Add ${field} to Light${
|
|
3114
|
+
message: `Add ${field} to Light${capitalize4(module)} projection fields.`
|
|
2264
3115
|
} : {
|
|
2265
3116
|
code: "add-field-light-projection-choice",
|
|
2266
3117
|
kind: "manual-action",
|
|
2267
3118
|
target: paths.constant,
|
|
2268
|
-
action: `Pass includeInLight=true when users should see ${field} in list/card data. Without it, the field can exist on ${
|
|
3119
|
+
action: `Pass includeInLight=true when users should see ${field} in list/card data. Without it, the field can exist on ${capitalize4(module)}Input but stay absent from Light${capitalize4(module)} projections.`,
|
|
2269
3120
|
confidence: "medium",
|
|
2270
3121
|
message: `${module}.${field} is not selected for list/card projection data.`
|
|
2271
3122
|
},
|
|
@@ -2283,7 +3134,7 @@ var createAddFieldRecommendations = (inputs) => {
|
|
|
2283
3134
|
code: "add-field-ui-manual-review",
|
|
2284
3135
|
kind: "manual-action",
|
|
2285
3136
|
target: paths.template,
|
|
2286
|
-
action: `After apply, verify what users can see: Template form auto-edit only runs when a generated ${module}Form hook and Layout.Template field list are present. Unit/View cards are not auto-edited, so ${field} may be stored on ${
|
|
3137
|
+
action: `After apply, verify what users can see: Template form auto-edit only runs when a generated ${module}Form hook and Layout.Template field list are present. Unit/View cards are not auto-edited, so ${field} may be stored on ${capitalize4(module)} but not shown in list/card UI until you place it in the local card layout.`,
|
|
2287
3138
|
confidence: "medium",
|
|
2288
3139
|
message: `${app}:${module}.${field} may need UI review for user-visible Template, Unit, and View behavior.`
|
|
2289
3140
|
},
|
|
@@ -2382,6 +3233,16 @@ var createWorkflowPlan = (spec, rawInputs) => {
|
|
|
2382
3233
|
});
|
|
2383
3234
|
continue;
|
|
2384
3235
|
}
|
|
3236
|
+
const namePattern = nameInputPatterns[name];
|
|
3237
|
+
if (namePattern && typeof value === "string" && !namePattern.test(value)) {
|
|
3238
|
+
diagnostics.push({
|
|
3239
|
+
severity: "error",
|
|
3240
|
+
code: "workflow-input-invalid",
|
|
3241
|
+
input: name,
|
|
3242
|
+
message: `Workflow ${spec.name} input "${name}" must be a plain name without dots, slashes or spaces, not ${JSON.stringify(value)}.`
|
|
3243
|
+
});
|
|
3244
|
+
continue;
|
|
3245
|
+
}
|
|
2385
3246
|
if (inputSpec.allowedValues && typeof value === "string" && !inputSpec.allowedValues.includes(value)) {
|
|
2386
3247
|
diagnostics.push({
|
|
2387
3248
|
severity: "error",
|
|
@@ -2435,6 +3296,45 @@ var createWorkflowPlan = (spec, rawInputs) => {
|
|
|
2435
3296
|
approval: workflowPlanApproval
|
|
2436
3297
|
};
|
|
2437
3298
|
};
|
|
3299
|
+
var planString = (inputs, name) => typeof inputs[name] === "string" ? inputs[name] : null;
|
|
3300
|
+
var planStrings = (inputs, name) => Array.isArray(inputs[name]) ? inputs[name] : null;
|
|
3301
|
+
var inspectWorkflowPlan = async (workspace, plan) => {
|
|
3302
|
+
if (plan.workflow !== "add-mutation" && plan.workflow !== "create-interaction")
|
|
3303
|
+
return plan;
|
|
3304
|
+
const app = planString(plan.inputs, "app");
|
|
3305
|
+
if (!app)
|
|
3306
|
+
return plan;
|
|
3307
|
+
const sys = await resolveWorkflowSys(workspace, app).catch(() => null);
|
|
3308
|
+
if (!sys)
|
|
3309
|
+
return {
|
|
3310
|
+
...plan,
|
|
3311
|
+
diagnostics: [
|
|
3312
|
+
...plan.diagnostics,
|
|
3313
|
+
{
|
|
3314
|
+
severity: "error",
|
|
3315
|
+
code: "workflow-target-missing",
|
|
3316
|
+
input: "app",
|
|
3317
|
+
message: `No app or library named ${app}.`
|
|
3318
|
+
}
|
|
3319
|
+
]
|
|
3320
|
+
};
|
|
3321
|
+
const inspected = plan.workflow === "add-mutation" ? await MutationScaffold.build(sys, {
|
|
3322
|
+
module: planString(plan.inputs, "module"),
|
|
3323
|
+
mutation: planString(plan.inputs, "mutation"),
|
|
3324
|
+
guards: planStrings(plan.inputs, "guard"),
|
|
3325
|
+
withCalls: planStrings(plan.inputs, "with"),
|
|
3326
|
+
afterCalls: planStrings(plan.inputs, "after")
|
|
3327
|
+
}, { strict: false }) : { ...await InteractionScaffold.build(sys, planString(plan.inputs, "interaction")), recommendations: [] };
|
|
3328
|
+
const failedInputs = new Set(plan.diagnostics.filter((diagnostic) => diagnostic.severity === "error").map((diagnostic) => diagnostic.input));
|
|
3329
|
+
return {
|
|
3330
|
+
...plan,
|
|
3331
|
+
diagnostics: [
|
|
3332
|
+
...plan.diagnostics,
|
|
3333
|
+
...inspected.diagnostics.filter((diagnostic) => !diagnostic.input || !failedInputs.has(diagnostic.input))
|
|
3334
|
+
],
|
|
3335
|
+
recommendations: [...plan.recommendations, ...inspected.recommendations]
|
|
3336
|
+
};
|
|
3337
|
+
};
|
|
2438
3338
|
// pkgs/@akanjs/devkit/workflow/render.ts
|
|
2439
3339
|
var listOr = (items, render, empty = "- none") => items?.length ? items.map(render) : [empty];
|
|
2440
3340
|
var renderDiagnostic = (diagnostic) => `- [${diagnostic.severity}] ${diagnostic.code}: ${diagnostic.message}`;
|
|
@@ -2448,7 +3348,11 @@ var renderRecommendation = (recommendation) => {
|
|
|
2448
3348
|
var renderWorkflowList = (specs) => [
|
|
2449
3349
|
"# Akan Workflows",
|
|
2450
3350
|
"",
|
|
2451
|
-
...specs.flatMap((spec) => [
|
|
3351
|
+
...specs.flatMap((spec) => [
|
|
3352
|
+
`- \`${spec.name}\`: ${spec.description}`,
|
|
3353
|
+
` - When: ${spec.whenToUse}`,
|
|
3354
|
+
...spec.replacesRules?.length ? [` - Fixes: ${spec.replacesRules.map((rule) => `\`${rule}\``).join(", ")}`] : []
|
|
3355
|
+
]),
|
|
2452
3356
|
""
|
|
2453
3357
|
].join(`
|
|
2454
3358
|
`);
|
|
@@ -2460,8 +3364,14 @@ var renderWorkflowExplain = (spec) => [
|
|
|
2460
3364
|
"## When To Use",
|
|
2461
3365
|
spec.whenToUse,
|
|
2462
3366
|
"",
|
|
3367
|
+
...spec.replacesRules?.length ? [
|
|
3368
|
+
"## Replaces Rules",
|
|
3369
|
+
"This path is the fix when lint or the gate reports:",
|
|
3370
|
+
...spec.replacesRules.map((rule) => `- \`${rule}\``),
|
|
3371
|
+
""
|
|
3372
|
+
] : [],
|
|
2463
3373
|
"## Inputs",
|
|
2464
|
-
...Object.entries(spec.inputs).map(([name, input]) => `- \`${name}\`${input.required ? " (required)" : ""}: ${input.description}${input.allowedValues ? ` Allowed: ${input.allowedValues.join(", ")}.` : ""}`),
|
|
3374
|
+
...Object.entries(spec.inputs).map(([name, input]) => `- \`${name}\`${camelToKebabCase(name) === name ? "" : ` (\`--${camelToKebabCase(name)}\`)`}${input.required ? " (required)" : ""}: ${input.description}${input.allowedValues ? ` Allowed: ${input.allowedValues.join(", ")}.` : ""}`),
|
|
2465
3375
|
"",
|
|
2466
3376
|
"## Optional Surfaces",
|
|
2467
3377
|
...Object.entries(spec.optionalSurfaces ?? {}).map(([name, mode]) => `- \`${name}\`: ${mode}`),
|
|
@@ -2752,4 +3662,4 @@ for (const candidate of toolingRolloutCandidates) {
|
|
|
2752
3662
|
if (isRestrictedCandidate(candidate))
|
|
2753
3663
|
restrictedCandidates.set(candidate.packageName, candidate);
|
|
2754
3664
|
}
|
|
2755
|
-
export { jsonText, workflowStatus, compactDiagnostics, workflowPlanApproval, createWorkflowApplyReport, workflowCommandsForPlan, workflowPathsForPlan, workflowRunArtifactPath, writeWorkflowRunArtifact, workflowSyncDir, generatedFilePathsForTarget, writeGeneratedSyncState, readWorkflowRunArtifact, createWorkflowBaselineSummary, createWorkflowValidationRunReport, createDryRunWorkflowApplyReport, createRepairReport, sourceFile, moduleComponentName, moduleSourcePaths, generatedFilesForSync, validationCommandsForTarget, nextActionsForTarget, createPrimitiveWriteReport, createPassedPrimitiveReport, scalarChangedFiles, bilingualLabelForField, bilingualDescriptionForField, normalizeFieldType, ensureNamedImport, ensureBaseImport, ensureBaseTypeImport, coerceFieldDefault, fieldExpression, viaBuilderParameterName, insertIntoObject, insertLightProjectionField, insertTemplateField, ensureEnumImport, insertEnumClass, insertDictionaryModelField, hasConstantInputField, hasDictionaryModelField, ensureConstantTypeImport, insertDictionaryEnum, parseValues, hasSourceParseErrors, hasClassMethod, insertClassMethod, hasSignalFactoryEntry, insertSignalFactoryEntry, buildAkanModuleContextIndex, addFieldUiPolicyForType, createWorkflowStepRegistry, WorkflowExecutor, listWorkflowSpecs, getWorkflowSpec, compactWorkflowInputs, createWorkflowPlan, renderWorkflowList, renderWorkflowExplain, renderWorkflowPlan, renderWorkflowApply, renderWorkflowValidation, renderRepairReport, renderWorkflowRunArtifact, renderPrimitiveReport, toolingRolloutGate };
|
|
3665
|
+
export { InteractionScaffold, jsonText, workflowStatus, compactDiagnostics, workflowPlanApproval, createWorkflowApplyReport, workflowCommandsForPlan, workflowPathsForPlan, workflowRunArtifactPath, writeWorkflowRunArtifact, workflowSyncDir, generatedFilePathsForTarget, writeGeneratedSyncState, readWorkflowRunArtifact, createWorkflowBaselineSummary, createWorkflowValidationRunReport, createDryRunWorkflowApplyReport, createRepairReport, sourceFile, moduleComponentName, moduleSourcePaths, generatedFilesForSync, validationCommandsForTarget, nextActionsForTarget, createPrimitiveWriteReport, createPassedPrimitiveReport, scalarChangedFiles, bilingualLabelForField, bilingualDescriptionForField, normalizeFieldType, ensureNamedImport, ensureBaseImport, ensureBaseTypeImport, coerceFieldDefault, fieldExpression, viaBuilderParameterName, insertIntoObject, insertLightProjectionField, insertTemplateField, ensureEnumImport, insertEnumClass, insertDictionaryModelField, hasConstantInputField, hasDictionaryModelField, ensureConstantTypeImport, insertDictionaryEnum, parseValues, hasSourceParseErrors, hasClassMethod, insertClassMethod, hasSignalFactoryEntry, insertSignalFactoryEntry, buildAkanModuleContextIndex, addFieldUiPolicyForType, createWorkflowStepRegistry, WorkflowExecutor, MutationScaffold, isWorkflowSysName, isWorkflowModuleName, listWorkflowSpecs, getWorkflowSpec, compactWorkflowInputs, createWorkflowPlan, inspectWorkflowPlan, renderWorkflowList, renderWorkflowExplain, renderWorkflowPlan, renderWorkflowApply, renderWorkflowValidation, renderRepairReport, renderWorkflowRunArtifact, renderPrimitiveReport, toolingRolloutGate };
|