@akanjs/cli 3.2.0-rc.3 → 3.2.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.
Files changed (144) hide show
  1. package/.build-stamp +2 -1
  2. package/CodeAgent-c17abdbf.js +11 -0
  3. package/{CodeTui-wv9yf7eq.js → CodeTui-jed1nj82.js} +822 -666
  4. package/README.ko.md +26 -1
  5. package/README.md +26 -1
  6. package/TunnelShare-mbfcaqg0.js +18 -0
  7. package/agent.command-9whnc6vb.js +56 -0
  8. package/akanCode.js +12 -12
  9. package/appExecutor-020cyesq.js +11 -0
  10. package/{application.command-6515t682.js → application.command-4eqvyxkw.js} +77 -36
  11. package/{applicationBuildRunner-bqbyeg84.js → applicationBuildRunner-frtcrqfd.js} +18 -13
  12. package/buildBatch.proc.js +26 -11
  13. package/{cloud.command-32esk0v1.js → cloud.command-hbvmeezn.js} +31 -28
  14. package/cloud.script-9kmbr3d6.js +35 -0
  15. package/{code.command-xk7rwq2x.js → code.command-0ayrenk4.js} +14 -9
  16. package/{context.command-jwenkkf0.js → context.command-php852kf.js} +28 -23
  17. package/context.runner-nngmn7c0.js +34 -0
  18. package/{dependencyScanner-78sq8m4q.js → dependencyScanner-ge10gb52.js} +2 -2
  19. package/{devTui-cd03z4mx.js → devTui-rf374y2w.js} +1 -1
  20. package/{fileSys-zpvt5gtf.js → fileSys-q22646yc.js} +1 -1
  21. package/{guideline.command-w6yqpdec.js → guideline.command-w1grfwh7.js} +9 -4
  22. package/guidelines/agentRule/agentRule.instruction.md +29 -12
  23. package/guidelines/akanApi/akanApi.instruction.md +5 -3
  24. package/guidelines/conventions/core.md +23 -5
  25. package/guidelines/conventions/rules/app.md +4 -1
  26. package/guidelines/conventions/rules/page.md +5 -0
  27. package/guidelines/conventions/rules/ts.md +3 -3
  28. package/guidelines/errorCodes/errorCodes.instruction.md +158 -0
  29. package/guidelines/fieldRule/fieldRule.instruction.md +2 -1
  30. package/guidelines/mcpRule/mcpRule.instruction.md +96 -2
  31. package/guidelines/pageRule/pageRule.instruction.md +15 -1
  32. package/guidelines/runtimeRule/runtimeRule.instruction.md +12 -6
  33. package/guidelines/transportRule/transportRule.instruction.md +8 -1
  34. package/incrementalBuilder.proc.js +574 -410
  35. package/{index-w15mg3km.js → index-0dm25wvf.js} +1 -1
  36. package/{index-xrmrvafh.js → index-0gaj78wn.js} +808 -694
  37. package/{index-j1hjb477.js → index-11d7nh8a.js} +1 -1
  38. package/{index-hj6w4ka1.js → index-1p81ecbz.js} +1 -1
  39. package/{index-ygrdw6jw.js → index-1pjwsh2g.js} +65 -8
  40. package/{index-43acpsc7.js → index-28nk8w3j.js} +12 -12
  41. package/{index-qd7xn2bk.js → index-2ny1e95c.js} +2 -2
  42. package/{index-8gm4yag8.js → index-42jhx2ya.js} +6 -6
  43. package/{index-2rqyrvcy.js → index-4st0hq72.js} +62 -33
  44. package/{index-bak9f2br.js → index-5d57kx0s.js} +15 -11
  45. package/{index-bdmgqzb5.js → index-6469101k.js} +58 -29
  46. package/{index-7kmbqp0b.js → index-6pxmcaq8.js} +1 -1
  47. package/{index-54s6knqe.js → index-6zb17wcm.js} +12 -10
  48. package/{index-0ba8nj4d.js → index-7bs463x7.js} +50 -38
  49. package/{index-y725zb1a.js → index-7v7tvgt7.js} +196 -168
  50. package/{index-r0a604h4.js → index-99kjwyma.js} +1 -1
  51. package/{index-2mrn1mrg.js → index-9f3reh2y.js} +1 -1
  52. package/{index-386canwe.js → index-9rv2zt48.js} +186 -121
  53. package/{index-20wvskt8.js → index-9wab2ngg.js} +1 -1
  54. package/{index-2eym1yjb.js → index-9wjrwjgz.js} +288 -209
  55. package/{index-kcpk2d20.js → index-at6haq2x.js} +1474 -1139
  56. package/{index-6h775rv3.js → index-ba2xd32s.js} +53 -12
  57. package/{index-yf9wc28h.js → index-bejy9zyc.js} +1 -1
  58. package/{index-ngpt3zz3.js → index-bj8s07s7.js} +525 -440
  59. package/{index-bns3wcpc.js → index-by2tvsq6.js} +1 -1
  60. package/{index-vbhx60x5.js → index-cb91b6d8.js} +2140 -2165
  61. package/index-dss3ds74.js +127 -0
  62. package/{index-e22zedc2.js → index-f16kr6vj.js} +3 -3
  63. package/{index-ny2k80mv.js → index-ffa52fwf.js} +1 -1
  64. package/{index-djc5nxpy.js → index-fp5xf6ef.js} +6 -6
  65. package/{index-qrk06tfp.js → index-g45y5f3e.js} +2 -2
  66. package/{index-8jpc5fqv.js → index-g7jgd4xs.js} +2 -2
  67. package/index-j4yvgfhr.js +70 -0
  68. package/{index-ytpmk3pb.js → index-jgj31xvw.js} +18 -11
  69. package/{index-j6eeh5d7.js → index-knpm8sdm.js} +5 -5
  70. package/{index-s34v3y28.js → index-m3t28rt3.js} +11 -11
  71. package/{index-dpgywgeq.js → index-m5gg0wzv.js} +27 -16
  72. package/index-na8r4a27.js +30 -0
  73. package/{index-h0p6n4k1.js → index-nm7nt9vm.js} +3 -3
  74. package/{index-j4hkbzj6.js → index-p06kfhdf.js} +6 -6
  75. package/{index-35j83zkd.js → index-p5zh7pmc.js} +2 -2
  76. package/{index-cmg5ngqa.js → index-p7beqww9.js} +2 -2
  77. package/{index-zhkcab5a.js → index-prgvqqxe.js} +580 -364
  78. package/{index-wfmpxke3.js → index-qssq2d41.js} +2775 -3677
  79. package/{index-sc0g6zbm.js → index-rwgqba9p.js} +24 -11
  80. package/{index-zcdmnfrf.js → index-s3m89wt2.js} +9 -9
  81. package/{index-v50xjbbe.js → index-t4d0ckde.js} +1 -1
  82. package/{index-9p260r4e.js → index-trffs83s.js} +538 -250
  83. package/{index-ddk49ypz.js → index-v929w7j7.js} +133 -49
  84. package/index-va90m8nd.js +25 -0
  85. package/index-vjbne22r.js +80 -0
  86. package/{index-h7hehkw6.js → index-xczjdng6.js} +3 -1
  87. package/{index-39jz41jb.js → index-xs9a3ddt.js} +3 -3
  88. package/{index-84c2pgak.js → index-yvzm8mby.js} +94 -82
  89. package/{index-wr9magsr.js → index-yxkjsyx8.js} +3 -3
  90. package/index-ze48c0vd.js +788 -0
  91. package/{index-ygdbn9jn.js → index-zyb0ebm4.js} +1 -1
  92. package/index.js +29 -24
  93. package/libExecutor-tq994592.js +10 -0
  94. package/{library.command-qs8beggh.js → library.command-x219mhcx.js} +9 -4
  95. package/{localRegistry.command-hz4ged9n.js → localRegistry.command-zvdcejhn.js} +30 -24
  96. package/{module.command-z9js77m2.js → module.command-k6cwcm7g.js} +17 -8
  97. package/{package.command-zqenq8c0.js → package.command-vw7x09f8.js} +13 -8
  98. package/package.json +2 -2
  99. package/{page.command-t0nx1jat.js → page.command-gf06paq2.js} +9 -4
  100. package/{pipeline.command-2yjeas7m.js → pipeline.command-y07dgj9b.js} +14 -8
  101. package/pkgExecutor-stde3yc3.js +10 -0
  102. package/{primitive.command-v5kypwy4.js → primitive.command-edydvh07.js} +13 -8
  103. package/{projectTypecheck-s9hhe5sa.js → projectTypecheck-mk8wefvd.js} +2 -1
  104. package/{prompter-qrwx1p17.js → prompter-qyggfhqd.js} +2 -2
  105. package/{quality.command-q55j2htd.js → quality.command-mdb45vyr.js} +23 -16
  106. package/{recipeScanner-4b69ybe0.js → recipeScanner-rrx69awy.js} +1 -1
  107. package/{repair.command-7ssbbdq2.js → repair.command-kvtaeecy.js} +13 -8
  108. package/{routeSourceValidator-4h947v7c.js → routeSourceValidator-8n6j1vn7.js} +4 -2
  109. package/{scalar.command-p5jb7z57.js → scalar.command-sjt9p5e1.js} +11 -6
  110. package/skills/akan-debug/SKILL.md +10 -3
  111. package/skills/akan-err/SKILL.md +7 -0
  112. package/skills/akan-mcp/SKILL.md +14 -2
  113. package/skills/akan-scaffold/SKILL.md +2 -2
  114. package/skills/akan-transport/SKILL.md +2 -0
  115. package/skills/akan-validate/SKILL.md +1 -0
  116. package/{subspace.command-7wxy6ptj.js → subspace.command-mkkqync4.js} +29 -23
  117. package/templates/app/page/_layout.tsx +13 -0
  118. package/templates/app/page/styles.css.template +40 -0
  119. package/templates/appSample/page/_index.tsx +9 -9
  120. package/templates/appSample/page/_layout.tsx +1 -0
  121. package/templates/appSample/page/styles.css.template +40 -5
  122. package/templates/appSample/ui/Recipe/jellyButton.ts +1 -1
  123. package/templates/biomeForm.ts +1 -1
  124. package/templates/env/_env.server.type.ts +1 -1
  125. package/templates/facetIndex/index.ts +2 -37
  126. package/templates/lib/sig.ts +0 -4
  127. package/templates/lib/useClient.ts +1 -1
  128. package/templates/workspaceRoot/AGENTS.md.template +2 -1
  129. package/{tunnel.command-22g11n0x.js → tunnel.command-tr5b3030.js} +17 -12
  130. package/{typeChecker-s640r6c0.js → typeChecker-bfrd1n9n.js} +1 -1
  131. package/typecheck.proc.js +6 -3
  132. package/{verify.command-m0wnndd7.js → verify.command-0p9h8tpp.js} +26 -20
  133. package/{workflow.command-jx8dqs9n.js → workflow.command-9mfcwqzj.js} +37 -19
  134. package/{workspace.command-ca9kfyt3.js → workspace.command-5hjtmcfs.js} +61 -54
  135. package/CodeAgent-e9c712an.js +0 -11
  136. package/TunnelShare-zkfkrw8w.js +0 -14
  137. package/agent.command-9erafkcb.js +0 -51
  138. package/cloud.script-arsagnq6.js +0 -30
  139. package/context.runner-mqpp67br.js +0 -29
  140. package/index-x3x31df8.js +0 -14
  141. /package/templates/{appSample → app}/public/fonts/Pretendard-Bold.woff2 +0 -0
  142. /package/templates/{appSample → app}/public/fonts/Pretendard-Medium.woff2 +0 -0
  143. /package/templates/{appSample → app}/public/fonts/Pretendard-Regular.woff2 +0 -0
  144. /package/templates/{appSample → app}/public/fonts/Pretendard-SemiBold.woff2 +0 -0
@@ -1,19 +1,21 @@
1
1
  // @bun
2
2
  import {
3
- AppExecutor,
4
- LibExecutor
5
- } from "./index-wfmpxke3.js";
3
+ AppExecutor2
4
+ } from "./index-ze48c0vd.js";
5
+ import {
6
+ LibExecutor2
7
+ } from "./index-na8r4a27.js";
6
8
  import {
7
9
  createAst,
8
10
  AkanIndex
9
- } from "./index-9p260r4e.js";
11
+ } from "./index-trffs83s.js";
10
12
  import {
11
13
  sysNamePattern,
12
14
  identifierPattern
13
- } from "./index-x3x31df8.js";
15
+ } from "./index-va90m8nd.js";
14
16
  import {
15
17
  camelToKebabCase
16
- } from "./index-386canwe.js";
18
+ } from "./index-9rv2zt48.js";
17
19
 
18
20
  // pkgs/@akanjs/devkit/workflow/artifacts.ts
19
21
  import { capitalize as capitalize2 } from "akanjs/common";
@@ -184,11 +186,9 @@ var createWorkflowApplyReport = ({
184
186
  nextActions = [],
185
187
  plan
186
188
  }) => {
187
- const validationCommands = recommendedValidationCommands ?? commands;
188
- const nextActionsWithIntent = nextActions.map((action) => ({
189
- ...action,
190
- action: inferNextActionCode(action, diagnostics)
191
- }));
189
+ const status = workflowStatus(diagnostics);
190
+ const validationCommands = status === "failed" ? [] : recommendedValidationCommands ?? commands;
191
+ const nextActionsWithIntent = nextActions.map((action) => ({ ...action, action: inferNextActionCode(action, diagnostics) })).filter((action) => status !== "failed" || action.action !== "validate");
192
192
  if (sourceChangeBlocked(diagnostics) && !nextActionsWithIntent.some((action) => action.action === "blocked")) {
193
193
  nextActionsWithIntent.unshift({
194
194
  command: `akan workflow explain ${workflow}`,
@@ -198,12 +198,12 @@ var createWorkflowApplyReport = ({
198
198
  }
199
199
  const orderedNextActions = uniqueBy(nextActionsWithIntent, (action) => action.command).sort((left, right) => nextActionPriority(left, diagnostics) - nextActionPriority(right, diagnostics));
200
200
  const sourceFilesChanged = uniqueBy(changedFiles, (file) => `${file.action}:${file.path}:${file.reason}`);
201
- const generatedFilesSynced = uniqueBy(generatedFiles, (file) => `${file.action}:${file.path}:${file.reason}`);
201
+ const generatedFilesSynced = status === "failed" ? [] : uniqueBy(generatedFiles, (file) => `${file.action}:${file.path}:${file.reason}`);
202
202
  return {
203
203
  schemaVersion: 1,
204
204
  workflow,
205
205
  mode,
206
- status: workflowStatus(diagnostics),
206
+ status,
207
207
  summary: {
208
208
  sourceFilesChanged,
209
209
  generatedFilesSynced
@@ -531,15 +531,12 @@ var createRepairReport = ({
531
531
  });
532
532
  // pkgs/@akanjs/devkit/workflow/executor.ts
533
533
  import { capitalize as capitalize3 } from "akanjs/common";
534
- import ts4 from "typescript";
534
+ import ts7 from "typescript";
535
535
 
536
- // pkgs/@akanjs/devkit/workflow/moduleIndex.ts
537
- import { access } from "fs/promises";
538
- import path from "path";
539
- import ts3 from "typescript";
536
+ // pkgs/@akanjs/devkit/workflow/constantSource.ts
537
+ import ts4 from "typescript";
540
538
 
541
- // pkgs/@akanjs/devkit/workflow/source.ts
542
- import { lowerlize as lowerlize2 } from "akanjs/common";
539
+ // pkgs/@akanjs/devkit/workflow/fieldOrder.ts
543
540
  import ts2 from "typescript";
544
541
 
545
542
  // pkgs/@akanjs/devkit/workflow/sourceAst.ts
@@ -553,130 +550,121 @@ var {
553
550
  firstObjectReturnedByArrow,
554
551
  heritageCall
555
552
  } = createAst(ts);
556
-
557
- // pkgs/@akanjs/devkit/workflow/source.ts
558
- var getSysRoot = (sys) => `${sys.type}s/${sys.name}`;
559
- var sourceFile = (sys, path, action, reason) => ({
560
- path: `${getSysRoot(sys)}/${path}`,
561
- action,
562
- reason
563
- });
564
- var moduleComponentName = (moduleName) => moduleName.replace(/[-_]+/g, " ").replace(/(?<=^|\s)[a-zA-Z0-9]/g, (char) => char.toUpperCase()).replace(/\s+/g, "");
565
- var moduleSourcePaths = (moduleName) => {
566
- const componentName = moduleComponentName(moduleName);
567
- return {
568
- abstract: `lib/${moduleName}/${moduleName}.abstract.md`,
569
- constant: `lib/${moduleName}/${moduleName}.constant.ts`,
570
- dictionary: `lib/${moduleName}/${moduleName}.dictionary.ts`,
571
- document: `lib/${moduleName}/${moduleName}.document.ts`,
572
- service: `lib/${moduleName}/${moduleName}.service.ts`,
573
- signal: `lib/${moduleName}/${moduleName}.signal.ts`,
574
- store: `lib/${moduleName}/${moduleName}.store.ts`,
575
- template: `lib/${moduleName}/${componentName}.Template.tsx`,
576
- unit: `lib/${moduleName}/${componentName}.Unit.tsx`,
577
- util: `lib/${moduleName}/${componentName}.Util.tsx`,
578
- view: `lib/${moduleName}/${componentName}.View.tsx`,
579
- zone: `lib/${moduleName}/${componentName}.Zone.tsx`
553
+ var hasParseDiagnostics = (source) => (source.parseDiagnostics ?? []).length > 0;
554
+ var hasSourceParseErrors = (content, fileName = "source.ts") => hasParseDiagnostics(sourceFileFor(fileName, content));
555
+ var findClassDeclaration = (source, className) => {
556
+ let found = null;
557
+ const visit = (node) => {
558
+ if (found)
559
+ return;
560
+ if (ts.isClassDeclaration(node) && node.name?.text === className) {
561
+ found = node;
562
+ return;
563
+ }
564
+ ts.forEachChild(node, visit);
580
565
  };
566
+ ts.forEachChild(source, visit);
567
+ return found;
581
568
  };
582
- var generatedFilesForSync = (sys, reason = "Generated files may change after sync.") => generatedFilePathsForTarget(getSysRoot(sys), reason);
583
- var validationCommandsForTarget = (target) => [
584
- { command: `akan verify ${target}`, reason: "Sync, lint, typecheck and build the target in one run." }
585
- ];
586
- var nextActionsForTarget = (target) => [
587
- { command: `akan verify ${target}`, reason: "Refresh generated files and validate the target in one run." }
588
- ];
589
- var createPrimitiveWriteReport = ({
590
- command,
591
- status,
592
- changedFiles = [],
593
- generatedFiles = [],
594
- validationCommands = [],
595
- diagnostics = [],
596
- nextActions = []
597
- }) => ({
598
- schemaVersion: 1,
599
- command,
600
- status: status ?? (diagnostics.some((diagnostic) => diagnostic.severity === "error") ? "failed" : "passed"),
601
- changedFiles,
602
- generatedFiles,
603
- validationCommands,
604
- diagnostics,
605
- nextActions
606
- });
607
- var createPassedPrimitiveReport = ({
608
- command,
609
- changedFiles,
610
- generatedFiles,
611
- target,
612
- nextActions
613
- }) => createPrimitiveWriteReport({
614
- command,
615
- changedFiles,
616
- generatedFiles: generatedFiles ?? [],
617
- validationCommands: validationCommandsForTarget(target),
618
- diagnostics: [],
619
- nextActions: nextActions ?? nextActionsForTarget(target)
620
- });
621
- var scalarChangedFiles = (sys, scalarName, files) => Object.values(files).map((file) => sourceFile(sys, `lib/__scalar/${scalarName}/${file.filename}`, "create", "Scalar source file was created."));
622
- var titleize = (value) => value.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[-_]+/g, " ").replace(/\b\w/g, (char) => char.toUpperCase());
623
- var koLabels = {
624
- amount: "\uAE08\uC561",
625
- budget: "\uC608\uC0B0",
626
- category: "\uCE74\uD14C\uACE0\uB9AC",
627
- content: "\uB0B4\uC6A9",
628
- count: "\uAC1C\uC218",
629
- createdAt: "\uC0DD\uC131\uC77C",
630
- date: "\uB0A0\uC9DC",
631
- description: "\uC124\uBA85",
632
- due: "\uB9C8\uAC10\uC77C",
633
- dueAt: "\uB9C8\uAC10\uC77C",
634
- email: "\uC774\uBA54\uC77C",
635
- enabled: "\uD65C\uC131\uD654",
636
- endAt: "\uC885\uB8CC\uC77C",
637
- id: "ID",
638
- name: "\uC774\uB984",
639
- owner: "\uB2F4\uB2F9\uC790",
640
- priority: "\uC6B0\uC120\uC21C\uC704",
641
- project: "\uD504\uB85C\uC81D\uD2B8",
642
- rating: "\uD3C9\uC810",
643
- startAt: "\uC2DC\uC791\uC77C",
644
- status: "\uC0C1\uD0DC",
645
- title: "\uC81C\uBAA9",
646
- updatedAt: "\uC218\uC815\uC77C"
569
+ var firstHeritageCall = (node) => {
570
+ const expression = (node.heritageClauses?.flatMap((clause) => [...clause.types]) ?? [])[0]?.expression;
571
+ return expression && ts.isCallExpression(expression) ? expression : null;
647
572
  };
648
- var splitFieldWords = (fieldName) => fieldName.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[-_]+/g, " ").split(/\s+/).map((word) => word.trim()).filter(Boolean);
649
- var koLabelForField = (fieldName) => {
650
- if (koLabels[fieldName])
651
- return koLabels[fieldName];
652
- const words = splitFieldWords(fieldName);
653
- const translated = words.map((word) => koLabels[word] ?? koLabels[lowerlize2(word)] ?? null);
654
- return translated.every(Boolean) ? translated.join(" ") : null;
573
+ var factoryArrowOf = (call) => {
574
+ const arg = call.arguments.find((argument) => ts.isArrowFunction(argument) || ts.isFunctionExpression(argument));
575
+ return arg && (ts.isArrowFunction(arg) || ts.isFunctionExpression(arg)) ? arg : null;
655
576
  };
656
- var bilingualLabelForField = (fieldName) => {
657
- const en = titleize(fieldName);
658
- return { en, ko: koLabelForField(fieldName) ?? en };
577
+
578
+ // pkgs/@akanjs/devkit/workflow/sourceText.ts
579
+ var spliceText = (content, start, end, replacement) => `${content.slice(0, start)}${replacement}${content.slice(end)}`;
580
+ var lineStartAt = (content, position) => content.lastIndexOf(`
581
+ `, Math.max(0, position - 1)) + 1;
582
+ var lineEndAt = (content, position) => {
583
+ const end = content.indexOf(`
584
+ `, position);
585
+ return end < 0 ? content.length : end + 1;
659
586
  };
660
- var bilingualDescriptionForField = (fieldName) => {
661
- const label = bilingualLabelForField(fieldName);
662
- return {
663
- en: `Enter ${label.en.toLowerCase()}.`,
664
- ko: `${label.ko} \uAC12\uC744 \uC785\uB825\uD569\uB2C8\uB2E4.`
665
- };
587
+ var lineIndentAt = (content, position) => /^[ \t]*/.exec(content.slice(lineStartAt(content, position)))?.[0] ?? "";
588
+
589
+ // pkgs/@akanjs/devkit/workflow/fieldOrder.ts
590
+ var fieldOrderingPriority = [
591
+ "id",
592
+ "name",
593
+ "title",
594
+ "status",
595
+ "category",
596
+ "description",
597
+ "content",
598
+ "startAt",
599
+ "dueAt",
600
+ "endAt",
601
+ "createdAt",
602
+ "updatedAt"
603
+ ];
604
+ var locatedObject = (source, objectLiteral) => ({
605
+ objectStart: objectLiteral.getStart(source),
606
+ objectEnd: objectLiteral.getEnd(),
607
+ fields: objectLiteral.properties.map((property) => {
608
+ const name = propertyName(property);
609
+ if (!name)
610
+ return null;
611
+ return {
612
+ name,
613
+ start: property.getStart(source),
614
+ fullStart: property.getFullStart(),
615
+ end: property.getEnd()
616
+ };
617
+ }).filter((field) => field !== null)
618
+ });
619
+ var priorityOf = (fieldName) => {
620
+ const priority = fieldOrderingPriority.indexOf(fieldName);
621
+ return priority < 0 ? null : priority;
666
622
  };
667
- var normalizeFieldType = (typeName) => {
668
- const normalizedTypes = {
669
- string: "String",
670
- boolean: "Boolean",
671
- date: "Date",
672
- int: "Int",
673
- integer: "Int",
674
- float: "Float",
675
- double: "Float",
676
- decimal: "Float"
677
- };
678
- return normalizedTypes[typeName.toLowerCase()] ?? typeName;
623
+ var insertionIndexForFieldOrder = (fieldNames, newFieldName) => {
624
+ const newPriority = priorityOf(newFieldName);
625
+ if (newPriority !== null) {
626
+ const greaterPriorityIndex = fieldNames.findIndex((name) => {
627
+ const existingPriority = priorityOf(name);
628
+ return existingPriority !== null && existingPriority > newPriority;
629
+ });
630
+ if (greaterPriorityIndex >= 0)
631
+ return greaterPriorityIndex;
632
+ const lastPriorityIndex = fieldNames.reduce((lastIndex, name, index) => {
633
+ const existingPriority = priorityOf(name);
634
+ return existingPriority !== null ? index : lastIndex;
635
+ }, -1);
636
+ return lastPriorityIndex + 1;
637
+ }
638
+ const lastNonPriorityIndex = fieldNames.reduce((lastIndex, name, index) => priorityOf(name) === null ? index : lastIndex, -1);
639
+ return lastNonPriorityIndex >= 0 ? lastNonPriorityIndex + 1 : fieldNames.length;
640
+ };
641
+ var insertOrderedFieldLine = (content, locator, fieldName, line, options) => {
642
+ if (locator.fields.some((field) => field.name === fieldName))
643
+ return content;
644
+ const insertIndex = insertionIndexForFieldOrder(locator.fields.map((field) => field.name), fieldName);
645
+ const formattedLine = line.trim();
646
+ if (locator.fields.length === 0) {
647
+ return spliceText(content, locator.objectStart, locator.objectEnd, `{
648
+ ${options.fieldIndent}${formattedLine}
649
+ ${options.closingIndent}}`);
650
+ }
651
+ const beforeField = locator.fields[insertIndex];
652
+ if (beforeField) {
653
+ const leadingComments = ts2.getLeadingCommentRanges(content, beforeField.fullStart) ?? [];
654
+ const insertAt = lineStartAt(content, leadingComments[0]?.pos ?? beforeField.start);
655
+ const indent = lineIndentAt(content, beforeField.start) || options.fieldIndent;
656
+ return spliceText(content, insertAt, insertAt, `${indent}${formattedLine}
657
+ `);
658
+ }
659
+ const afterField = locator.fields[locator.fields.length - 1];
660
+ const insertAt = lineEndAt(content, afterField.end);
661
+ const indent = lineIndentAt(content, afterField.start) || options.fieldIndent;
662
+ return spliceText(content, insertAt, insertAt, `${indent}${formattedLine}
663
+ `);
679
664
  };
665
+
666
+ // pkgs/@akanjs/devkit/workflow/sourceImports.ts
667
+ import ts3 from "typescript";
680
668
  var importOrder = (a, b) => {
681
669
  const [lowerA, lowerB] = [a.toLowerCase(), b.toLowerCase()];
682
670
  if (lowerA !== lowerB)
@@ -698,7 +686,7 @@ var ensureImportDeclaration = (content, moduleSpecifier, clause) => {
698
686
  if (content.includes(line))
699
687
  return content;
700
688
  const source = sourceFileFor("source.ts", content);
701
- 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() }] : []);
689
+ const imports = source.statements.filter((statement) => ts3.isImportDeclaration(statement)).flatMap((statement) => ts3.isStringLiteral(statement.moduleSpecifier) ? [{ specifier: statement.moduleSpecifier.text, start: statement.getStart(source), end: statement.getEnd() }] : []);
702
690
  const isRelative = (specifier) => specifier.startsWith(".");
703
691
  const peers = imports.filter((entry) => isRelative(entry.specifier) === isRelative(moduleSpecifier));
704
692
  const before = peers.find((entry) => importOrder(entry.specifier, moduleSpecifier) > 0);
@@ -721,249 +709,67 @@ ${line}
721
709
  `);
722
710
  };
723
711
  var ensureBaseImport = (content, name) => ensureNamedImport(content, "akanjs/base", name);
724
- var ensureBaseTypeImport = (content, typeName) => {
725
- if (typeName !== "Int" && typeName !== "Float")
712
+ var findNamedImport = (source, moduleSpecifier, { valueOnly = false } = {}) => {
713
+ for (const statement of source.statements) {
714
+ if (!ts3.isImportDeclaration(statement) || !ts3.isStringLiteral(statement.moduleSpecifier))
715
+ continue;
716
+ if (statement.moduleSpecifier.text !== moduleSpecifier)
717
+ continue;
718
+ if (valueOnly && statement.importClause?.isTypeOnly)
719
+ continue;
720
+ const namedBindings = statement.importClause?.namedBindings;
721
+ if (!namedBindings || !ts3.isNamedImports(namedBindings))
722
+ continue;
723
+ return {
724
+ names: namedBindings.elements.map((element) => element.name.text),
725
+ elements: namedBindings.elements.map((element) => ({ name: element.name.text, text: element.getText(source) })),
726
+ namedBindingsStart: namedBindings.getStart(source),
727
+ namedBindingsEnd: namedBindings.getEnd()
728
+ };
729
+ }
730
+ return null;
731
+ };
732
+ var ensureEnumImport = (content) => {
733
+ if (content.includes("enumOf"))
726
734
  return content;
727
- return ensureBaseImport(content, typeName);
735
+ const baseImport = /import \{ ([^{}]+) \} from "akanjs\/base";/.exec(content);
736
+ if (baseImport) {
737
+ const names = baseImport[1]?.split(",").map((name) => name.trim()) ?? [];
738
+ return content.replace(baseImport[0], `import { ${[...names, "enumOf"].sort().join(", ")} } from "akanjs/base";`);
739
+ }
740
+ return `import { enumOf } from "akanjs/base";
741
+ ${content}`;
728
742
  };
729
- var numericDefault = (typeName, rawDefault) => {
730
- if (typeof rawDefault === "number") {
731
- if (!Number.isFinite(rawDefault))
732
- return null;
733
- if (typeName === "Int" && !Number.isInteger(rawDefault))
734
- return null;
735
- return String(rawDefault);
736
- }
737
- if (typeof rawDefault !== "string")
738
- return null;
739
- const trimmed = rawDefault.trim();
740
- if (!trimmed || !Number.isFinite(Number(trimmed)))
741
- return null;
742
- if (typeName === "Int" && !/^-?\d+$/.test(trimmed))
743
- return null;
744
- return trimmed;
745
- };
746
- var booleanDefault = (rawDefault) => {
747
- if (typeof rawDefault === "boolean")
748
- return String(rawDefault);
749
- if (typeof rawDefault !== "string")
750
- return null;
751
- const lowered = rawDefault.trim().toLowerCase();
752
- return lowered === "true" || lowered === "false" ? lowered : null;
753
- };
754
- var dateDefault = (rawDefault) => {
755
- if (typeof rawDefault === "number" && Number.isFinite(rawDefault))
756
- return `() => dayjs(${rawDefault})`;
757
- if (typeof rawDefault !== "string")
758
- return null;
759
- const trimmed = rawDefault.trim();
760
- if (!trimmed)
761
- return null;
762
- if (trimmed === "now")
763
- return "() => dayjs()";
764
- if (!Number.isNaN(Date.parse(trimmed)))
765
- return `() => dayjs(${JSON.stringify(trimmed)})`;
766
- return null;
767
- };
768
- var coerceFieldDefault = (typeName, defaultValue, options = {}) => {
769
- const normalizedType = typeName.toLowerCase() === "enum" ? "enum" : normalizeFieldType(typeName);
770
- if (defaultValue === undefined || defaultValue === null || defaultValue === "") {
771
- return { expression: null, normalized: false, normalizedType };
772
- }
773
- if (normalizedType === "Int" || normalizedType === "Float") {
774
- const expression = numericDefault(normalizedType, defaultValue);
775
- if (expression !== null)
776
- return { expression, normalized: typeof defaultValue === "string", normalizedType };
777
- return {
778
- expression: null,
779
- normalized: false,
780
- normalizedType,
781
- diagnostic: {
782
- severity: "error",
783
- code: "primitive-default-value-invalid",
784
- input: "default",
785
- failureScope: "source-change",
786
- message: `Default value for ${normalizedType} must be a numeric literal. Received: ${JSON.stringify(defaultValue)}.`
787
- }
788
- };
789
- }
790
- if (normalizedType === "Boolean") {
791
- const expression = booleanDefault(defaultValue);
792
- if (expression !== null)
793
- return { expression, normalized: typeof defaultValue === "string", normalizedType };
794
- return {
795
- expression: null,
796
- normalized: false,
797
- normalizedType,
798
- diagnostic: {
799
- severity: "error",
800
- code: "primitive-default-value-invalid",
801
- input: "default",
802
- failureScope: "source-change",
803
- message: `Default value for Boolean must be true or false. Received: ${JSON.stringify(defaultValue)}.`
804
- }
805
- };
806
- }
807
- if (normalizedType === "Date") {
808
- const expression = dateDefault(defaultValue);
809
- if (expression !== null)
810
- return { expression, normalized: true, normalizedType };
811
- return {
812
- expression: null,
813
- normalized: false,
814
- normalizedType,
815
- diagnostic: {
816
- severity: "error",
817
- code: "primitive-default-value-invalid",
818
- input: "default",
819
- failureScope: "source-change",
820
- message: `Default value for Date must be "now", a timestamp, or a parseable date string. Received: ${JSON.stringify(defaultValue)}.`
821
- }
822
- };
823
- }
824
- if (normalizedType === "enum") {
825
- if (typeof defaultValue === "string" && options.enumValues?.includes(defaultValue)) {
826
- return { expression: JSON.stringify(defaultValue), normalized: false, normalizedType };
827
- }
828
- return {
829
- expression: null,
830
- normalized: false,
831
- normalizedType,
832
- diagnostic: {
833
- severity: "error",
834
- code: "primitive-default-value-invalid",
835
- input: "default",
836
- failureScope: "source-change",
837
- message: `Default value for enum must be one of: ${(options.enumValues ?? []).join(", ")}. Received: ${JSON.stringify(defaultValue)}.`
838
- }
839
- };
743
+ var ensureConstantTypeImport = (content, constantPath, typeName) => {
744
+ if (new RegExp(`import type \\{[^}]*\\b${typeName}\\b[^}]*\\} from "${constantPath}";`).test(content))
745
+ return content;
746
+ const importPattern = new RegExp(`import type \\{ ([^}]+) \\} from "${constantPath}";`);
747
+ const existingImport = content.match(importPattern);
748
+ if (existingImport !== null) {
749
+ const names = existingImport[1]?.split(",").map((name) => name.trim()) ?? [];
750
+ return content.replace(existingImport[0], `import type { ${[...names, typeName].sort().join(", ")} } from "${constantPath}";`);
840
751
  }
841
- return {
842
- expression: JSON.stringify(String(defaultValue)),
843
- normalized: typeof defaultValue !== "string",
844
- normalizedType
845
- };
846
- };
847
- var fieldExpression = (typeName, defaultValue, options = {}) => {
848
- const typeExpression = normalizeFieldType(typeName);
849
- const defaultExpression = coerceFieldDefault(options.enumValues ? "enum" : typeExpression, defaultValue, options).expression;
850
- const defaultOption = defaultExpression ? `, { default: ${defaultExpression} }` : "";
851
- return `${options.builderName ?? "field"}(${typeExpression}${defaultOption})`;
852
- };
853
- var fieldOrderingPriority = [
854
- "id",
855
- "name",
856
- "title",
857
- "status",
858
- "category",
859
- "description",
860
- "content",
861
- "startAt",
862
- "dueAt",
863
- "endAt",
864
- "createdAt",
865
- "updatedAt"
866
- ];
867
- var hasParseDiagnostics = (source) => (source.parseDiagnostics ?? []).length > 0;
868
- var spliceText = (content, start, end, replacement) => `${content.slice(0, start)}${replacement}${content.slice(end)}`;
869
- var lineStartAt = (content, position) => content.lastIndexOf(`
870
- `, Math.max(0, position - 1)) + 1;
871
- var lineEndAt = (content, position) => {
872
- const end = content.indexOf(`
873
- `, position);
874
- return end < 0 ? content.length : end + 1;
752
+ return `import type { ${typeName} } from "${constantPath}";
753
+ ${content}`;
875
754
  };
876
- var lineIndentAt = (content, position) => /^[ \t]*/.exec(content.slice(lineStartAt(content, position)))?.[0] ?? "";
877
- var locatedObject = (source, objectLiteral) => ({
878
- objectStart: objectLiteral.getStart(source),
879
- objectEnd: objectLiteral.getEnd(),
880
- fields: objectLiteral.properties.map((property) => {
881
- const name = propertyName(property);
882
- if (!name)
883
- return null;
884
- return {
885
- name,
886
- start: property.getStart(source),
887
- fullStart: property.getFullStart(),
888
- end: property.getEnd()
889
- };
890
- }).filter((field) => field !== null)
891
- });
755
+
756
+ // pkgs/@akanjs/devkit/workflow/constantSource.ts
892
757
  var findConstantInputObject = (source, className) => {
893
758
  let locator = null;
894
759
  const visit = (node) => {
895
760
  if (locator)
896
761
  return;
897
- if (!ts2.isClassDeclaration(node) || node.name?.text !== className) {
898
- ts2.forEachChild(node, visit);
762
+ if (!ts4.isClassDeclaration(node) || node.name?.text !== className) {
763
+ ts4.forEachChild(node, visit);
899
764
  return;
900
765
  }
901
766
  const viaCall = heritageCall(node);
902
- const callback = viaCall?.arguments.find((arg) => ts2.isArrowFunction(arg) || ts2.isFunctionExpression(arg));
767
+ const callback = viaCall?.arguments.find((arg) => ts4.isArrowFunction(arg) || ts4.isFunctionExpression(arg));
903
768
  const objectLiteral = callback ? firstObjectReturnedByArrow(callback) : null;
904
769
  if (objectLiteral)
905
770
  locator = locatedObject(source, objectLiteral);
906
771
  };
907
- ts2.forEachChild(source, visit);
908
- return locator;
909
- };
910
- var chainMethodsForCall = (node) => {
911
- if (ts2.isAsExpression(node) || ts2.isParenthesizedExpression(node))
912
- return chainMethodsForCall(node.expression);
913
- if (!ts2.isCallExpression(node))
914
- return [];
915
- if (ts2.isPropertyAccessExpression(node.expression)) {
916
- return [...chainMethodsForCall(node.expression.expression), node.expression.name.text];
917
- }
918
- const name = expressionName(node.expression);
919
- return name ? [name] : [];
920
- };
921
- var outermostFluentCall = (node) => {
922
- let current = node;
923
- while (ts2.isPropertyAccessExpression(current.parent) && current.parent.expression === current && ts2.isCallExpression(current.parent.parent) && current.parent.parent.expression === current.parent) {
924
- current = current.parent.parent;
925
- }
926
- return current;
927
- };
928
- var protectedDictionaryChainOrder = ["model", "slice", "enum", "error", "translate"];
929
- var dictionaryChainOrderValid = (chainMethods) => {
930
- const protectedOrder = new Map(protectedDictionaryChainOrder.map((method, index) => [method, index]));
931
- let lastOrder = -1;
932
- for (const method of chainMethods) {
933
- const order = protectedOrder.get(method);
934
- if (order === undefined)
935
- continue;
936
- if (order < lastOrder)
937
- return false;
938
- lastOrder = order;
939
- }
940
- return true;
941
- };
942
- var findDictionaryModelObject = (source, moduleClassName) => findDictionaryStageObject(source, "model", moduleClassName);
943
- var findDictionaryStageObject = (source, stage, typeName) => {
944
- let locator = null;
945
- const visit = (node) => {
946
- if (locator)
947
- return;
948
- if (!ts2.isCallExpression(node) || callExpressionName(node) !== stage) {
949
- ts2.forEachChild(node, visit);
950
- return;
951
- }
952
- const typeArgument = node.typeArguments?.[0];
953
- if (!typeArgument || typeArgument.getText(source) !== typeName) {
954
- ts2.forEachChild(node, visit);
955
- return;
956
- }
957
- const callback = node.arguments.find((arg) => ts2.isArrowFunction(arg) || ts2.isFunctionExpression(arg));
958
- const objectLiteral = callback ? firstObjectReturnedByArrow(callback) : null;
959
- if (objectLiteral) {
960
- locator = {
961
- ...locatedObject(source, objectLiteral),
962
- chainMethods: chainMethodsForCall(outermostFluentCall(node))
963
- };
964
- }
965
- };
966
- ts2.forEachChild(source, visit);
772
+ ts4.forEachChild(source, visit);
967
773
  return locator;
968
774
  };
969
775
  var findLightProjectionArray = (source, moduleClassName) => {
@@ -971,118 +777,52 @@ var findLightProjectionArray = (source, moduleClassName) => {
971
777
  const visit = (node) => {
972
778
  if (locator)
973
779
  return;
974
- if (!ts2.isClassDeclaration(node) || node.name?.text !== `Light${moduleClassName}`) {
975
- ts2.forEachChild(node, visit);
780
+ if (!ts4.isClassDeclaration(node) || node.name?.text !== `Light${moduleClassName}`) {
781
+ ts4.forEachChild(node, visit);
976
782
  return;
977
783
  }
978
784
  const viaCall = heritageCall(node);
979
785
  const projectionArg = viaCall?.arguments.find((arg) => {
980
- const expression = ts2.isAsExpression(arg) ? arg.expression : arg;
981
- return ts2.isArrayLiteralExpression(expression);
786
+ const expression = ts4.isAsExpression(arg) ? arg.expression : arg;
787
+ return ts4.isArrayLiteralExpression(expression);
982
788
  });
983
- const arrayLiteral = projectionArg ? ts2.isAsExpression(projectionArg) ? projectionArg.expression : projectionArg : null;
984
- if (!projectionArg || !arrayLiteral || !ts2.isArrayLiteralExpression(arrayLiteral))
789
+ const arrayLiteral = projectionArg ? ts4.isAsExpression(projectionArg) ? projectionArg.expression : projectionArg : null;
790
+ if (!projectionArg || !arrayLiteral || !ts4.isArrayLiteralExpression(arrayLiteral))
985
791
  return;
986
792
  locator = {
987
793
  projectionStart: projectionArg.getStart(source),
988
794
  projectionEnd: projectionArg.getEnd(),
989
- fields: arrayLiteral.elements.map((element) => ts2.isStringLiteralLike(element) ? element.text : null).filter((field) => field !== null)
795
+ fields: arrayLiteral.elements.map((element) => ts4.isStringLiteralLike(element) ? element.text : null).filter((field) => field !== null)
990
796
  };
991
797
  };
992
- ts2.forEachChild(source, visit);
798
+ ts4.forEachChild(source, visit);
993
799
  return locator;
994
800
  };
995
- var findNamedImport = (source, moduleSpecifier, { valueOnly = false } = {}) => {
996
- for (const statement of source.statements) {
997
- if (!ts2.isImportDeclaration(statement) || !ts2.isStringLiteral(statement.moduleSpecifier))
998
- continue;
999
- if (statement.moduleSpecifier.text !== moduleSpecifier)
1000
- continue;
1001
- if (valueOnly && statement.importClause?.isTypeOnly)
1002
- continue;
1003
- const namedBindings = statement.importClause?.namedBindings;
1004
- if (!namedBindings || !ts2.isNamedImports(namedBindings))
1005
- continue;
1006
- return {
1007
- names: namedBindings.elements.map((element) => element.name.text),
1008
- elements: namedBindings.elements.map((element) => ({ name: element.name.text, text: element.getText(source) })),
1009
- namedBindingsStart: namedBindings.getStart(source),
1010
- namedBindingsEnd: namedBindings.getEnd()
1011
- };
1012
- }
1013
- return null;
1014
- };
1015
801
  var fieldExpressionBuilder = (property) => {
1016
- if (!ts2.isPropertyAssignment(property))
802
+ if (!ts4.isPropertyAssignment(property))
1017
803
  return null;
1018
- const initializer = ts2.isAsExpression(property.initializer) ? property.initializer.expression : property.initializer;
1019
- if (!ts2.isCallExpression(initializer))
804
+ const initializer = ts4.isAsExpression(property.initializer) ? property.initializer.expression : property.initializer;
805
+ if (!ts4.isCallExpression(initializer))
1020
806
  return null;
1021
807
  return expressionName(initializer.expression);
1022
808
  };
1023
- var priorityOf = (fieldName) => {
1024
- const priority = fieldOrderingPriority.indexOf(fieldName);
1025
- return priority < 0 ? null : priority;
1026
- };
1027
- var insertionIndexForFieldOrder = (fieldNames, newFieldName) => {
1028
- const newPriority = priorityOf(newFieldName);
1029
- if (newPriority !== null) {
1030
- const greaterPriorityIndex = fieldNames.findIndex((name) => {
1031
- const existingPriority = priorityOf(name);
1032
- return existingPriority !== null && existingPriority > newPriority;
1033
- });
1034
- if (greaterPriorityIndex >= 0)
1035
- return greaterPriorityIndex;
1036
- const lastPriorityIndex = fieldNames.reduce((lastIndex, name, index) => {
1037
- const existingPriority = priorityOf(name);
1038
- return existingPriority !== null ? index : lastIndex;
1039
- }, -1);
1040
- return lastPriorityIndex + 1;
1041
- }
1042
- const lastNonPriorityIndex = fieldNames.reduce((lastIndex, name, index) => priorityOf(name) === null ? index : lastIndex, -1);
1043
- return lastNonPriorityIndex >= 0 ? lastNonPriorityIndex + 1 : fieldNames.length;
1044
- };
1045
- var insertOrderedFieldLine = (content, locator, fieldName, line, options) => {
1046
- if (locator.fields.some((field) => field.name === fieldName))
1047
- return content;
1048
- const insertIndex = insertionIndexForFieldOrder(locator.fields.map((field) => field.name), fieldName);
1049
- const formattedLine = line.trim();
1050
- if (locator.fields.length === 0) {
1051
- return spliceText(content, locator.objectStart, locator.objectEnd, `{
1052
- ${options.fieldIndent}${formattedLine}
1053
- ${options.closingIndent}}`);
1054
- }
1055
- const beforeField = locator.fields[insertIndex];
1056
- if (beforeField) {
1057
- const leadingComments = ts2.getLeadingCommentRanges(content, beforeField.fullStart) ?? [];
1058
- const insertAt = lineStartAt(content, leadingComments[0]?.pos ?? beforeField.start);
1059
- const indent = lineIndentAt(content, beforeField.start) || options.fieldIndent;
1060
- return spliceText(content, insertAt, insertAt, `${indent}${formattedLine}
1061
- `);
1062
- }
1063
- const afterField = locator.fields[locator.fields.length - 1];
1064
- const insertAt = lineEndAt(content, afterField.end);
1065
- const indent = lineIndentAt(content, afterField.start) || options.fieldIndent;
1066
- return spliceText(content, insertAt, insertAt, `${indent}${formattedLine}
1067
- `);
1068
- };
1069
809
  var viaBuilderParameterName = (content, className) => {
1070
810
  const source = sourceFileFor("constant.ts", content);
1071
811
  let builderName = null;
1072
812
  const visit = (node) => {
1073
813
  if (builderName !== null)
1074
814
  return;
1075
- if (!ts2.isClassDeclaration(node) || node.name?.text !== className) {
1076
- ts2.forEachChild(node, visit);
815
+ if (!ts4.isClassDeclaration(node) || node.name?.text !== className) {
816
+ ts4.forEachChild(node, visit);
1077
817
  return;
1078
818
  }
1079
819
  const viaCall = heritageCall(node);
1080
- const callback = viaCall?.arguments.find((arg) => ts2.isArrowFunction(arg) || ts2.isFunctionExpression(arg));
1081
- if (callback && (ts2.isArrowFunction(callback) || ts2.isFunctionExpression(callback))) {
820
+ const callback = viaCall?.arguments.find((arg) => ts4.isArrowFunction(arg) || ts4.isFunctionExpression(arg));
821
+ if (callback && (ts4.isArrowFunction(callback) || ts4.isFunctionExpression(callback))) {
1082
822
  builderName = nodeName(callback.parameters[0]?.name);
1083
823
  }
1084
824
  };
1085
- ts2.forEachChild(source, visit);
825
+ ts4.forEachChild(source, visit);
1086
826
  return builderName;
1087
827
  };
1088
828
  var inspectConstantStructure = (content, className, moduleClassName) => {
@@ -1093,12 +833,12 @@ var inspectConstantStructure = (content, className, moduleClassName) => {
1093
833
  const fields = [];
1094
834
  if (inputObject) {
1095
835
  const visit = (node) => {
1096
- if (!ts2.isClassDeclaration(node) || node.name?.text !== className) {
1097
- ts2.forEachChild(node, visit);
836
+ if (!ts4.isClassDeclaration(node) || node.name?.text !== className) {
837
+ ts4.forEachChild(node, visit);
1098
838
  return;
1099
839
  }
1100
840
  const viaCall = heritageCall(node);
1101
- const callback = viaCall?.arguments.find((arg) => ts2.isArrowFunction(arg) || ts2.isFunctionExpression(arg));
841
+ const callback = viaCall?.arguments.find((arg) => ts4.isArrowFunction(arg) || ts4.isFunctionExpression(arg));
1102
842
  const objectLiteral = callback ? firstObjectReturnedByArrow(callback) : null;
1103
843
  if (!objectLiteral)
1104
844
  return;
@@ -1109,7 +849,7 @@ var inspectConstantStructure = (content, className, moduleClassName) => {
1109
849
  return { name, expressionBuilder: fieldExpressionBuilder(property) };
1110
850
  }).filter((field) => field !== null));
1111
851
  };
1112
- ts2.forEachChild(source, visit);
852
+ ts4.forEachChild(source, visit);
1113
853
  }
1114
854
  return {
1115
855
  parseValid: !hasParseDiagnostics(source),
@@ -1120,17 +860,6 @@ var inspectConstantStructure = (content, className, moduleClassName) => {
1120
860
  baseImports: baseImport?.names ?? []
1121
861
  };
1122
862
  };
1123
- var inspectDictionaryStructure = (content, moduleClassName) => {
1124
- const source = sourceFileFor("dictionary.ts", content);
1125
- const modelObject = findDictionaryModelObject(source, moduleClassName);
1126
- return {
1127
- parseValid: !hasParseDiagnostics(source),
1128
- modelObjectFound: modelObject !== null,
1129
- chainOrderValid: modelObject ? dictionaryChainOrderValid(modelObject.chainMethods) : false,
1130
- chainMethods: modelObject?.chainMethods ?? [],
1131
- fields: modelObject?.fields.map((field) => field.name) ?? []
1132
- };
1133
- };
1134
863
  var insertIntoObject = (content, className, line) => {
1135
864
  const fieldName = /^([A-Za-z_$][\w$]*)\s*:/.exec(line.trim())?.[1];
1136
865
  if (!fieldName)
@@ -1155,42 +884,6 @@ ${nextFields.map((field) => ` ${JSON.stringify(field)},`).join(`
1155
884
  ] as const`;
1156
885
  return spliceText(content, locator.projectionStart, locator.projectionEnd, nextArray);
1157
886
  };
1158
- var insertTemplateField = ({
1159
- content,
1160
- moduleName,
1161
- moduleClassName,
1162
- fieldName,
1163
- component
1164
- }) => {
1165
- if (content.includes(`l("${moduleName}.${fieldName}")`) || content.includes(`.${fieldName}`))
1166
- return content;
1167
- const layoutEndIndex = content.indexOf(" </Layout.Template>");
1168
- if (layoutEndIndex < 0)
1169
- return null;
1170
- const formName = `${moduleName}Form`;
1171
- if (!content.includes(`const ${formName} = st.use.${moduleName}Form();`))
1172
- return null;
1173
- const fieldSetter = `st.do.set${moduleComponentName(fieldName)}On${moduleClassName}`;
1174
- const fieldBlock = ` <${component}
1175
- label={l("${moduleName}.${fieldName}")}
1176
- desc={l("${moduleName}.${fieldName}.desc")}
1177
- value={${formName}.${fieldName}}
1178
- onChange={${fieldSetter}}
1179
- />
1180
- `;
1181
- return `${content.slice(0, layoutEndIndex)}${fieldBlock}${content.slice(layoutEndIndex)}`;
1182
- };
1183
- var ensureEnumImport = (content) => {
1184
- if (content.includes("enumOf"))
1185
- return content;
1186
- const baseImport = /import \{ ([^{}]+) \} from "akanjs\/base";/.exec(content);
1187
- if (baseImport) {
1188
- const names = baseImport[1]?.split(",").map((name) => name.trim()) ?? [];
1189
- return content.replace(baseImport[0], `import { ${[...names, "enumOf"].sort().join(", ")} } from "akanjs/base";`);
1190
- }
1191
- return `import { enumOf } from "akanjs/base";
1192
- ${content}`;
1193
- };
1194
887
  var insertEnumClass = (content, enumClassName, enumName, values) => {
1195
888
  if (content.includes(`export class ${enumClassName} extends enumOf`))
1196
889
  return content;
@@ -1206,6 +899,135 @@ ${values.map((value) => ` ${JSON.stringify(value)},`).join(`
1206
899
  ${enumClass}`;
1207
900
  return `${content.slice(0, firstClassIndex)}${enumClass}${content.slice(firstClassIndex)}`;
1208
901
  };
902
+ var hasConstantInputField = (content, className, fieldName) => {
903
+ const source = sourceFileFor("constant.ts", content);
904
+ if (hasParseDiagnostics(source))
905
+ return false;
906
+ return findConstantInputObject(source, className)?.fields.some((field) => field.name === fieldName) ?? false;
907
+ };
908
+
909
+ // pkgs/@akanjs/devkit/workflow/dictionarySource.ts
910
+ import ts5 from "typescript";
911
+
912
+ // pkgs/@akanjs/devkit/workflow/fieldLabel.ts
913
+ import { lowerlize as lowerlize2 } from "akanjs/common";
914
+ var titleize = (value) => value.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[-_]+/g, " ").replace(/\b\w/g, (char) => char.toUpperCase());
915
+ var koLabels = {
916
+ amount: "\uAE08\uC561",
917
+ budget: "\uC608\uC0B0",
918
+ category: "\uCE74\uD14C\uACE0\uB9AC",
919
+ content: "\uB0B4\uC6A9",
920
+ count: "\uAC1C\uC218",
921
+ createdAt: "\uC0DD\uC131\uC77C",
922
+ date: "\uB0A0\uC9DC",
923
+ description: "\uC124\uBA85",
924
+ due: "\uB9C8\uAC10\uC77C",
925
+ dueAt: "\uB9C8\uAC10\uC77C",
926
+ email: "\uC774\uBA54\uC77C",
927
+ enabled: "\uD65C\uC131\uD654",
928
+ endAt: "\uC885\uB8CC\uC77C",
929
+ id: "ID",
930
+ name: "\uC774\uB984",
931
+ owner: "\uB2F4\uB2F9\uC790",
932
+ priority: "\uC6B0\uC120\uC21C\uC704",
933
+ project: "\uD504\uB85C\uC81D\uD2B8",
934
+ rating: "\uD3C9\uC810",
935
+ startAt: "\uC2DC\uC791\uC77C",
936
+ status: "\uC0C1\uD0DC",
937
+ title: "\uC81C\uBAA9",
938
+ updatedAt: "\uC218\uC815\uC77C"
939
+ };
940
+ var splitFieldWords = (fieldName) => fieldName.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[-_]+/g, " ").split(/\s+/).map((word) => word.trim()).filter(Boolean);
941
+ var koLabelForField = (fieldName) => {
942
+ if (koLabels[fieldName])
943
+ return koLabels[fieldName];
944
+ const words = splitFieldWords(fieldName);
945
+ const translated = words.map((word) => koLabels[word] ?? koLabels[lowerlize2(word)] ?? null);
946
+ return translated.every(Boolean) ? translated.join(" ") : null;
947
+ };
948
+ var bilingualLabelForField = (fieldName) => {
949
+ const en = titleize(fieldName);
950
+ return { en, ko: koLabelForField(fieldName) ?? en };
951
+ };
952
+ var bilingualDescriptionForField = (fieldName) => {
953
+ const label = bilingualLabelForField(fieldName);
954
+ return {
955
+ en: `Enter ${label.en.toLowerCase()}.`,
956
+ ko: `${label.ko} \uAC12\uC744 \uC785\uB825\uD569\uB2C8\uB2E4.`
957
+ };
958
+ };
959
+
960
+ // pkgs/@akanjs/devkit/workflow/dictionarySource.ts
961
+ var chainMethodsForCall = (node) => {
962
+ if (ts5.isAsExpression(node) || ts5.isParenthesizedExpression(node))
963
+ return chainMethodsForCall(node.expression);
964
+ if (!ts5.isCallExpression(node))
965
+ return [];
966
+ if (ts5.isPropertyAccessExpression(node.expression)) {
967
+ return [...chainMethodsForCall(node.expression.expression), node.expression.name.text];
968
+ }
969
+ const name = expressionName(node.expression);
970
+ return name ? [name] : [];
971
+ };
972
+ var outermostFluentCall = (node) => {
973
+ let current = node;
974
+ while (ts5.isPropertyAccessExpression(current.parent) && current.parent.expression === current && ts5.isCallExpression(current.parent.parent) && current.parent.parent.expression === current.parent) {
975
+ current = current.parent.parent;
976
+ }
977
+ return current;
978
+ };
979
+ var protectedDictionaryChainOrder = ["model", "slice", "enum", "error", "translate"];
980
+ var dictionaryChainOrderValid = (chainMethods) => {
981
+ const protectedOrder = new Map(protectedDictionaryChainOrder.map((method, index) => [method, index]));
982
+ let lastOrder = -1;
983
+ for (const method of chainMethods) {
984
+ const order = protectedOrder.get(method);
985
+ if (order === undefined)
986
+ continue;
987
+ if (order < lastOrder)
988
+ return false;
989
+ lastOrder = order;
990
+ }
991
+ return true;
992
+ };
993
+ var findDictionaryModelObject = (source, moduleClassName) => findDictionaryStageObject(source, "model", moduleClassName);
994
+ var findDictionaryStageObject = (source, stage, typeName) => {
995
+ let locator = null;
996
+ const visit = (node) => {
997
+ if (locator)
998
+ return;
999
+ if (!ts5.isCallExpression(node) || callExpressionName(node) !== stage) {
1000
+ ts5.forEachChild(node, visit);
1001
+ return;
1002
+ }
1003
+ const typeArgument = node.typeArguments?.[0];
1004
+ if (!typeArgument || typeArgument.getText(source) !== typeName) {
1005
+ ts5.forEachChild(node, visit);
1006
+ return;
1007
+ }
1008
+ const callback = node.arguments.find((arg) => ts5.isArrowFunction(arg) || ts5.isFunctionExpression(arg));
1009
+ const objectLiteral = callback ? firstObjectReturnedByArrow(callback) : null;
1010
+ if (objectLiteral) {
1011
+ locator = {
1012
+ ...locatedObject(source, objectLiteral),
1013
+ chainMethods: chainMethodsForCall(outermostFluentCall(node))
1014
+ };
1015
+ }
1016
+ };
1017
+ ts5.forEachChild(source, visit);
1018
+ return locator;
1019
+ };
1020
+ var inspectDictionaryStructure = (content, moduleClassName) => {
1021
+ const source = sourceFileFor("dictionary.ts", content);
1022
+ const modelObject = findDictionaryModelObject(source, moduleClassName);
1023
+ return {
1024
+ parseValid: !hasParseDiagnostics(source),
1025
+ modelObjectFound: modelObject !== null,
1026
+ chainOrderValid: modelObject ? dictionaryChainOrderValid(modelObject.chainMethods) : false,
1027
+ chainMethods: modelObject?.chainMethods ?? [],
1028
+ fields: modelObject?.fields.map((field) => field.name) ?? []
1029
+ };
1030
+ };
1209
1031
  var dictionaryModelFieldLine = (fieldName) => {
1210
1032
  const label = bilingualLabelForField(fieldName);
1211
1033
  const desc = bilingualDescriptionForField(fieldName);
@@ -1221,12 +1043,6 @@ var insertDictionaryModelField = (content, moduleClassName, fieldName) => {
1221
1043
  closingIndent: " "
1222
1044
  });
1223
1045
  };
1224
- var hasConstantInputField = (content, className, fieldName) => {
1225
- const source = sourceFileFor("constant.ts", content);
1226
- if (hasParseDiagnostics(source))
1227
- return false;
1228
- return findConstantInputObject(source, className)?.fields.some((field) => field.name === fieldName) ?? false;
1229
- };
1230
1046
  var hasDictionaryModelField = (content, moduleClassName, fieldName) => {
1231
1047
  const source = sourceFileFor("dictionary.ts", content);
1232
1048
  if (hasParseDiagnostics(source))
@@ -1244,28 +1060,16 @@ var insertDictionaryEndpointEntry = (content, moduleClassName, entryName, entryT
1244
1060
  return null;
1245
1061
  return insertOrderedFieldLine(content, locator, entryName, entryText, { fieldIndent: " ", closingIndent: " " });
1246
1062
  };
1247
- var ensureConstantTypeImport = (content, constantPath, typeName) => {
1248
- if (new RegExp(`import type \\{[^}]*\\b${typeName}\\b[^}]*\\} from "${constantPath}";`).test(content))
1249
- return content;
1250
- const importPattern = new RegExp(`import type \\{ ([^}]+) \\} from "${constantPath}";`);
1251
- const existingImport = content.match(importPattern);
1252
- if (existingImport !== null) {
1253
- const names = existingImport[1]?.split(",").map((name) => name.trim()) ?? [];
1254
- return content.replace(existingImport[0], `import type { ${[...names, typeName].sort().join(", ")} } from "${constantPath}";`);
1255
- }
1256
- return `import type { ${typeName} } from "${constantPath}";
1257
- ${content}`;
1258
- };
1259
1063
  var dictionaryChainOf = (node) => {
1260
- if (ts2.isCallExpression(node) && outermostFluentCall(node) === node && protectedDictionaryChainOrder.some((method) => chainMethodsForCall(node).includes(method)))
1064
+ if (ts5.isCallExpression(node) && outermostFluentCall(node) === node && protectedDictionaryChainOrder.some((method) => chainMethodsForCall(node).includes(method)))
1261
1065
  return node;
1262
- return ts2.forEachChild(node, dictionaryChainOf);
1066
+ return ts5.forEachChild(node, dictionaryChainOf);
1263
1067
  };
1264
1068
  var chainMethodNames = (call) => {
1265
- if (!ts2.isCallExpression(call) || !ts2.isPropertyAccessExpression(call.expression))
1069
+ if (!ts5.isCallExpression(call) || !ts5.isPropertyAccessExpression(call.expression))
1266
1070
  return [];
1267
1071
  const name = call.expression.name;
1268
- return [...chainMethodNames(call.expression.expression), ...ts2.isIdentifier(name) ? [name] : []];
1072
+ return [...chainMethodNames(call.expression.expression), ...ts5.isIdentifier(name) ? [name] : []];
1269
1073
  };
1270
1074
  var insertDictionaryEnum = (content, enumClassName, enumName, values) => {
1271
1075
  if (content.includes(`.enum<${enumClassName}>("${enumName}"`))
@@ -1292,152 +1096,171 @@ ${enumBlock.trimEnd()}`);
1292
1096
  return spliceText(content, dot, dot, `
1293
1097
  ${enumBlock}`);
1294
1098
  };
1295
- var parseValues = (value) => value?.split(",").map((item) => item.trim()).filter(Boolean) ?? [];
1296
- var hasSourceParseErrors = (content, fileName = "source.ts") => hasParseDiagnostics(sourceFileFor(fileName, content));
1297
- var findClassDeclaration = (source, className) => {
1298
- let found = null;
1299
- const visit = (node) => {
1300
- if (found)
1301
- return;
1302
- if (ts2.isClassDeclaration(node) && node.name?.text === className) {
1303
- found = node;
1304
- return;
1305
- }
1306
- ts2.forEachChild(node, visit);
1099
+
1100
+ // pkgs/@akanjs/devkit/workflow/fieldExpression.ts
1101
+ var normalizeFieldType = (typeName) => {
1102
+ const normalizedTypes = {
1103
+ string: "String",
1104
+ boolean: "Boolean",
1105
+ date: "Date",
1106
+ int: "Int",
1107
+ integer: "Int",
1108
+ float: "Float",
1109
+ double: "Float",
1110
+ decimal: "Float"
1307
1111
  };
1308
- ts2.forEachChild(source, visit);
1309
- return found;
1310
- };
1311
- var firstHeritageCall = (node) => {
1312
- const expression = (node.heritageClauses?.flatMap((clause) => [...clause.types]) ?? [])[0]?.expression;
1313
- return expression && ts2.isCallExpression(expression) ? expression : null;
1314
- };
1315
- var factoryArrowOf = (call) => {
1316
- const arg = call.arguments.find((argument) => ts2.isArrowFunction(argument) || ts2.isFunctionExpression(argument));
1317
- return arg && (ts2.isArrowFunction(arg) || ts2.isFunctionExpression(arg)) ? arg : null;
1318
- };
1319
- var hasClassMethod = (content, className, methodName) => {
1320
- const node = findClassDeclaration(sourceFileFor("service.ts", content), className);
1321
- return Boolean(node?.members.some((member) => ts2.isMethodDeclaration(member) && nodeName(member.name) === methodName));
1322
- };
1323
- var classMethodParameters = (content, className, methodName) => {
1324
- const source = sourceFileFor("service.ts", content);
1325
- const method = findClassDeclaration(source, className)?.members.find((member) => ts2.isMethodDeclaration(member) && nodeName(member.name) === methodName);
1326
- return method?.parameters.map((parameter) => ({
1327
- name: nodeName(parameter.name),
1328
- optional: !!parameter.questionToken || !!parameter.initializer || !!parameter.dotDotDotToken
1329
- })) ?? null;
1330
- };
1331
- var insertClassMethod = (content, className, methodBlock) => {
1332
- const source = sourceFileFor("service.ts", content);
1333
- const node = findClassDeclaration(source, className);
1334
- if (!node)
1335
- return null;
1336
- const closeBrace = node.getEnd() - 1;
1337
- if (content[closeBrace] !== "}")
1338
- return null;
1339
- const lead = content.slice(0, closeBrace).endsWith(`
1340
- `) ? "" : `
1341
- `;
1342
- return spliceText(content, closeBrace, closeBrace, `${lead}${methodBlock}
1343
- `);
1112
+ return normalizedTypes[typeName.toLowerCase()] ?? typeName;
1344
1113
  };
1345
- var arrowParamInnerRegion = (content, source, arrow) => {
1346
- if (arrow.parameters.length > 0) {
1347
- return {
1348
- start: arrow.parameters[0].getStart(source),
1349
- end: arrow.parameters[arrow.parameters.length - 1].getEnd()
1350
- };
1114
+ var numericDefault = (typeName, rawDefault) => {
1115
+ if (typeof rawDefault === "number") {
1116
+ if (!Number.isFinite(rawDefault))
1117
+ return null;
1118
+ if (typeName === "Int" && !Number.isInteger(rawDefault))
1119
+ return null;
1120
+ return String(rawDefault);
1351
1121
  }
1352
- const open = content.indexOf("(", arrow.getStart(source));
1353
- if (open < 0)
1354
- return null;
1355
- const close = content.indexOf(")", open);
1356
- if (close < 0)
1357
- return null;
1358
- return { start: open + 1, end: close };
1359
- };
1360
- var factoryParamEdit = (content, source, arrow, plan) => {
1361
- if (arrow.parameters.length > 1)
1362
- return null;
1363
- const region = arrowParamInnerRegion(content, source, arrow);
1364
- if (!region)
1122
+ if (typeof rawDefault !== "string")
1365
1123
  return null;
1366
- if (arrow.parameters.length === 0) {
1367
- return { ...region, text: plan.mode === "destructure" ? `{ ${plan.name} }` : plan.name };
1368
- }
1369
- const param = arrow.parameters[0];
1370
- if (plan.mode === "positional")
1371
- return nodeName(param.name) === plan.name ? "unchanged" : null;
1372
- if (!ts2.isObjectBindingPattern(param.name))
1124
+ const trimmed = rawDefault.trim();
1125
+ if (!trimmed || !Number.isFinite(Number(trimmed)))
1373
1126
  return null;
1374
- const names = param.name.elements.map((element) => ts2.isIdentifier(element.name) ? element.name.text : null);
1375
- if (names.some((name) => name === null))
1127
+ if (typeName === "Int" && !/^-?\d+$/.test(trimmed))
1376
1128
  return null;
1377
- if (names.includes(plan.name))
1378
- return "unchanged";
1379
- return {
1380
- start: param.getStart(source),
1381
- end: param.getEnd(),
1382
- text: `{ ${[...names, plan.name].join(", ")} }`
1383
- };
1384
- };
1385
- var factoryObjectOf = (source, className) => {
1386
- const node = findClassDeclaration(source, className);
1387
- const call = node ? firstHeritageCall(node) : null;
1388
- const arrow = call ? factoryArrowOf(call) : null;
1389
- const object = arrow ? firstObjectReturnedByArrow(arrow) : null;
1390
- return arrow && object ? { arrow, object } : null;
1391
- };
1392
- var hasSignalFactoryEntry = (content, className, entryName) => {
1393
- const located = factoryObjectOf(sourceFileFor("signal.ts", content), className);
1394
- return Boolean(located?.object.properties.some((property) => propertyName(property) === entryName));
1129
+ return trimmed;
1395
1130
  };
1396
- var insertSignalFactoryEntry = (content, className, entryName, entryLine, param) => {
1397
- const source = sourceFileFor("signal.ts", content);
1398
- const located = factoryObjectOf(source, className);
1399
- if (!located)
1131
+ var booleanDefault = (rawDefault) => {
1132
+ if (typeof rawDefault === "boolean")
1133
+ return String(rawDefault);
1134
+ if (typeof rawDefault !== "string")
1400
1135
  return null;
1401
- const locator = locatedObject(source, located.object);
1402
- if (locator.fields.some((field) => field.name === entryName))
1403
- return content;
1404
- const paramEdit = factoryParamEdit(content, source, located.arrow, param);
1405
- if (paramEdit === null)
1136
+ const lowered = rawDefault.trim().toLowerCase();
1137
+ return lowered === "true" || lowered === "false" ? lowered : null;
1138
+ };
1139
+ var dateDefault = (rawDefault) => {
1140
+ if (typeof rawDefault === "number" && Number.isFinite(rawDefault))
1141
+ return `() => dayjs(${rawDefault})`;
1142
+ if (typeof rawDefault !== "string")
1406
1143
  return null;
1407
- const withEntry = insertOrderedFieldLine(content, locator, entryName, entryLine, {
1408
- fieldIndent: " ",
1409
- closingIndent: ""
1410
- });
1411
- if (withEntry === content)
1144
+ const trimmed = rawDefault.trim();
1145
+ if (!trimmed)
1412
1146
  return null;
1413
- return paramEdit === "unchanged" ? withEntry : spliceText(withEntry, paramEdit.start, paramEdit.end, paramEdit.text);
1147
+ if (trimmed === "now")
1148
+ return "() => dayjs()";
1149
+ if (!Number.isNaN(Date.parse(trimmed)))
1150
+ return `() => dayjs(${JSON.stringify(trimmed)})`;
1151
+ return null;
1414
1152
  };
1415
- var appendTopLevelTestCases = (content, describeTitle, render) => {
1416
- const bunImport = findNamedImport(sourceFileFor("test.ts", content), "bun:test", { valueOnly: true });
1417
- const itName = !bunImport?.names.includes("it") && bunImport?.names.includes("test") ? "test" : "it";
1418
- const imported = ensureNamedImport(content, "bun:test", itName);
1419
- const source = sourceFileFor("test.ts", imported);
1420
- const body = source.statements.flatMap((statement) => {
1421
- if (!ts2.isExpressionStatement(statement) || !ts2.isCallExpression(statement.expression))
1422
- return [];
1423
- if (expressionName(statement.expression.expression) !== "describe")
1424
- return [];
1425
- const callback = factoryArrowOf(statement.expression);
1426
- return callback && ts2.isBlock(callback.body) ? [callback.body] : [];
1427
- })[0];
1428
- if (!body) {
1429
- const block = [`describe(${JSON.stringify(describeTitle)}, () => {`, ...render(itName, " "), "});", ""];
1430
- return `${ensureNamedImport(imported, "bun:test", "describe").trimEnd()}
1431
-
1432
- ${block.join(`
1433
- `)}`;
1153
+ var coerceFieldDefault = (typeName, defaultValue, options = {}) => {
1154
+ const normalizedType = typeName.toLowerCase() === "enum" ? "enum" : normalizeFieldType(typeName);
1155
+ if (defaultValue === undefined || defaultValue === null || defaultValue === "") {
1156
+ return { expression: null, normalized: false, normalizedType };
1157
+ }
1158
+ if (normalizedType === "Int" || normalizedType === "Float") {
1159
+ const expression = numericDefault(normalizedType, defaultValue);
1160
+ if (expression !== null)
1161
+ return { expression, normalized: typeof defaultValue === "string", normalizedType };
1162
+ return {
1163
+ expression: null,
1164
+ normalized: false,
1165
+ normalizedType,
1166
+ diagnostic: {
1167
+ severity: "error",
1168
+ code: "primitive-default-value-invalid",
1169
+ input: "default",
1170
+ failureScope: "source-change",
1171
+ message: `Default value for ${normalizedType} must be a numeric literal. Received: ${JSON.stringify(defaultValue)}.`
1172
+ }
1173
+ };
1174
+ }
1175
+ if (normalizedType === "Boolean") {
1176
+ const expression = booleanDefault(defaultValue);
1177
+ if (expression !== null)
1178
+ return { expression, normalized: typeof defaultValue === "string", normalizedType };
1179
+ return {
1180
+ expression: null,
1181
+ normalized: false,
1182
+ normalizedType,
1183
+ diagnostic: {
1184
+ severity: "error",
1185
+ code: "primitive-default-value-invalid",
1186
+ input: "default",
1187
+ failureScope: "source-change",
1188
+ message: `Default value for Boolean must be true or false. Received: ${JSON.stringify(defaultValue)}.`
1189
+ }
1190
+ };
1191
+ }
1192
+ if (normalizedType === "Date") {
1193
+ const expression = dateDefault(defaultValue);
1194
+ if (expression !== null)
1195
+ return { expression, normalized: true, normalizedType };
1196
+ return {
1197
+ expression: null,
1198
+ normalized: false,
1199
+ normalizedType,
1200
+ diagnostic: {
1201
+ severity: "error",
1202
+ code: "primitive-default-value-invalid",
1203
+ input: "default",
1204
+ failureScope: "source-change",
1205
+ message: `Default value for Date must be "now", a timestamp, or a parseable date string. Received: ${JSON.stringify(defaultValue)}.`
1206
+ }
1207
+ };
1208
+ }
1209
+ if (normalizedType === "enum") {
1210
+ if (typeof defaultValue === "string" && options.enumValues?.includes(defaultValue)) {
1211
+ return { expression: JSON.stringify(defaultValue), normalized: false, normalizedType };
1212
+ }
1213
+ return {
1214
+ expression: null,
1215
+ normalized: false,
1216
+ normalizedType,
1217
+ diagnostic: {
1218
+ severity: "error",
1219
+ code: "primitive-default-value-invalid",
1220
+ input: "default",
1221
+ failureScope: "source-change",
1222
+ message: `Default value for enum must be one of: ${(options.enumValues ?? []).join(", ")}. Received: ${JSON.stringify(defaultValue)}.`
1223
+ }
1224
+ };
1434
1225
  }
1435
- const firstStatement = body.statements[0];
1436
- const indent = firstStatement ? lineIndentAt(imported, firstStatement.getStart(source)) : `${lineIndentAt(imported, body.getStart(source))} `;
1437
- const insertAt = lineStartAt(imported, body.getEnd() - 1);
1438
- return spliceText(imported, insertAt, insertAt, `${render(itName, indent).join(`
1439
- `)}
1440
- `);
1226
+ return {
1227
+ expression: JSON.stringify(String(defaultValue)),
1228
+ normalized: typeof defaultValue !== "string",
1229
+ normalizedType
1230
+ };
1231
+ };
1232
+ var fieldExpression = (typeName, defaultValue, options = {}) => {
1233
+ const typeExpression = normalizeFieldType(typeName);
1234
+ const defaultExpression = coerceFieldDefault(options.enumValues ? "enum" : typeExpression, defaultValue, options).expression;
1235
+ const defaultOption = defaultExpression ? `, { default: ${defaultExpression} }` : "";
1236
+ return `${options.builderName ?? "field"}(${typeExpression}${defaultOption})`;
1237
+ };
1238
+ var parseValues = (value) => value?.split(",").map((item) => item.trim()).filter(Boolean) ?? [];
1239
+
1240
+ // pkgs/@akanjs/devkit/workflow/moduleIndex.ts
1241
+ import { access } from "fs/promises";
1242
+ import path from "path";
1243
+ import ts6 from "typescript";
1244
+
1245
+ // pkgs/@akanjs/devkit/workflow/modulePaths.ts
1246
+ var getSysRoot = (sys) => `${sys.type}s/${sys.name}`;
1247
+ var moduleComponentName = (moduleName) => moduleName.replace(/[-_]+/g, " ").replace(/(?<=^|\s)[a-zA-Z0-9]/g, (char) => char.toUpperCase()).replace(/\s+/g, "");
1248
+ var moduleSourcePaths = (moduleName) => {
1249
+ const componentName = moduleComponentName(moduleName);
1250
+ return {
1251
+ abstract: `lib/${moduleName}/${moduleName}.abstract.md`,
1252
+ constant: `lib/${moduleName}/${moduleName}.constant.ts`,
1253
+ dictionary: `lib/${moduleName}/${moduleName}.dictionary.ts`,
1254
+ document: `lib/${moduleName}/${moduleName}.document.ts`,
1255
+ service: `lib/${moduleName}/${moduleName}.service.ts`,
1256
+ signal: `lib/${moduleName}/${moduleName}.signal.ts`,
1257
+ store: `lib/${moduleName}/${moduleName}.store.ts`,
1258
+ template: `lib/${moduleName}/${componentName}.Template.tsx`,
1259
+ unit: `lib/${moduleName}/${componentName}.Unit.tsx`,
1260
+ util: `lib/${moduleName}/${componentName}.Util.tsx`,
1261
+ view: `lib/${moduleName}/${componentName}.View.tsx`,
1262
+ zone: `lib/${moduleName}/${componentName}.Zone.tsx`
1263
+ };
1441
1264
  };
1442
1265
 
1443
1266
  // pkgs/@akanjs/devkit/workflow/moduleIndex.ts
@@ -1474,7 +1297,7 @@ var parseDiagnosticsFor = (source, filePath) => {
1474
1297
  return parseDiagnostics.map((diagnostic) => ({
1475
1298
  severity: "error",
1476
1299
  code: "module-index-typescript-parse-error",
1477
- message: `TypeScript parse diagnostic TS${diagnostic.code} in ${filePath}: ${ts3.flattenDiagnosticMessageText(diagnostic.messageText, `
1300
+ message: `TypeScript parse diagnostic TS${diagnostic.code} in ${filePath}: ${ts6.flattenDiagnosticMessageText(diagnostic.messageText, `
1478
1301
  `)}`,
1479
1302
  context: { target: filePath, paths: [filePath] }
1480
1303
  }));
@@ -1493,32 +1316,32 @@ var spanFor = (source, file, node) => {
1493
1316
  };
1494
1317
  };
1495
1318
  var expressionSummary = (expression) => {
1496
- if (ts3.isAsExpression(expression))
1319
+ if (ts6.isAsExpression(expression))
1497
1320
  return expressionSummary(expression.expression);
1498
- if (ts3.isIdentifier(expression) || ts3.isPropertyAccessExpression(expression))
1321
+ if (ts6.isIdentifier(expression) || ts6.isPropertyAccessExpression(expression))
1499
1322
  return expressionName(expression) ?? "expression";
1500
- if (ts3.isArrayLiteralExpression(expression))
1323
+ if (ts6.isArrayLiteralExpression(expression))
1501
1324
  return "array-literal";
1502
- if (ts3.isObjectLiteralExpression(expression))
1325
+ if (ts6.isObjectLiteralExpression(expression))
1503
1326
  return "object-literal";
1504
- if (ts3.isStringLiteralLike(expression))
1327
+ if (ts6.isStringLiteralLike(expression))
1505
1328
  return "string-literal";
1506
- if (ts3.isNumericLiteral(expression))
1329
+ if (ts6.isNumericLiteral(expression))
1507
1330
  return "numeric-literal";
1508
- if (expression.kind === ts3.SyntaxKind.TrueKeyword || expression.kind === ts3.SyntaxKind.FalseKeyword) {
1331
+ if (expression.kind === ts6.SyntaxKind.TrueKeyword || expression.kind === ts6.SyntaxKind.FalseKeyword) {
1509
1332
  return "boolean-literal";
1510
1333
  }
1511
- if (ts3.isCallExpression(expression)) {
1334
+ if (ts6.isCallExpression(expression)) {
1512
1335
  const callee = expressionName(expression.expression);
1513
1336
  return callee ? `${callee}(...)` : "call-expression";
1514
1337
  }
1515
- return ts3.SyntaxKind[expression.kind] ?? "expression";
1338
+ return ts6.SyntaxKind[expression.kind] ?? "expression";
1516
1339
  };
1517
1340
  var typeSummaryForInitializer = (initializer) => {
1518
1341
  if (!initializer)
1519
1342
  return;
1520
- const expression = ts3.isAsExpression(initializer) ? initializer.expression : initializer;
1521
- if (!ts3.isCallExpression(expression))
1343
+ const expression = ts6.isAsExpression(initializer) ? initializer.expression : initializer;
1344
+ if (!ts6.isCallExpression(expression))
1522
1345
  return expressionSummary(expression);
1523
1346
  const callee = expressionName(expression.expression);
1524
1347
  const firstArg = expression.arguments[0];
@@ -1529,7 +1352,7 @@ var fieldsFromObject = (source, file, objectLiteral, kind) => objectLiteral.prop
1529
1352
  const name = propertyName(property);
1530
1353
  if (!name)
1531
1354
  return null;
1532
- const initializer = ts3.isPropertyAssignment(property) ? property.initializer : undefined;
1355
+ const initializer = ts6.isPropertyAssignment(property) ? property.initializer : undefined;
1533
1356
  return {
1534
1357
  name,
1535
1358
  kind,
@@ -1550,8 +1373,8 @@ var parseConstantIndex = (filePath, content, moduleClassName) => {
1550
1373
  let fields = [];
1551
1374
  let lightProjection;
1552
1375
  const visit = (node) => {
1553
- if (!ts3.isClassDeclaration(node) || !node.name) {
1554
- ts3.forEachChild(node, visit);
1376
+ if (!ts6.isClassDeclaration(node) || !node.name) {
1377
+ ts6.forEachChild(node, visit);
1555
1378
  return;
1556
1379
  }
1557
1380
  const className = node.name.text;
@@ -1561,8 +1384,8 @@ var parseConstantIndex = (filePath, content, moduleClassName) => {
1561
1384
  if (!viaCall)
1562
1385
  return;
1563
1386
  inputViaFound = true;
1564
- const callback = viaCall.arguments.find((arg) => ts3.isArrowFunction(arg) || ts3.isFunctionExpression(arg));
1565
- if (callback && (ts3.isArrowFunction(callback) || ts3.isFunctionExpression(callback))) {
1387
+ const callback = viaCall.arguments.find((arg) => ts6.isArrowFunction(arg) || ts6.isFunctionExpression(arg));
1388
+ if (callback && (ts6.isArrowFunction(callback) || ts6.isFunctionExpression(callback))) {
1566
1389
  inputBuilderFound = true;
1567
1390
  builderName = nodeName(callback.parameters[0]?.name) ?? null;
1568
1391
  const objectLiteral = firstObjectReturnedByArrow(callback);
@@ -1576,15 +1399,15 @@ var parseConstantIndex = (filePath, content, moduleClassName) => {
1576
1399
  return;
1577
1400
  if (className === `Light${moduleClassName}`) {
1578
1401
  const projectionArg = viaCall.arguments.find((arg) => {
1579
- const expression = ts3.isAsExpression(arg) ? arg.expression : arg;
1580
- return ts3.isArrayLiteralExpression(expression);
1402
+ const expression = ts6.isAsExpression(arg) ? arg.expression : arg;
1403
+ return ts6.isArrayLiteralExpression(expression);
1581
1404
  });
1582
- const arrayLiteral = projectionArg ? ts3.isAsExpression(projectionArg) ? projectionArg.expression : projectionArg : null;
1583
- if (arrayLiteral && ts3.isArrayLiteralExpression(arrayLiteral)) {
1405
+ const arrayLiteral = projectionArg ? ts6.isAsExpression(projectionArg) ? projectionArg.expression : projectionArg : null;
1406
+ if (arrayLiteral && ts6.isArrayLiteralExpression(arrayLiteral)) {
1584
1407
  lightProjection = {
1585
1408
  className,
1586
1409
  sourceSpan: spanFor(source, filePath, arrayLiteral),
1587
- fields: arrayLiteral.elements.map((element, order) => ts3.isStringLiteralLike(element) ? {
1410
+ fields: arrayLiteral.elements.map((element, order) => ts6.isStringLiteralLike(element) ? {
1588
1411
  name: element.text,
1589
1412
  kind: "lightProjection",
1590
1413
  order,
@@ -1595,7 +1418,7 @@ var parseConstantIndex = (filePath, content, moduleClassName) => {
1595
1418
  }
1596
1419
  }
1597
1420
  };
1598
- ts3.forEachChild(source, visit);
1421
+ ts6.forEachChild(source, visit);
1599
1422
  if (!inputClass) {
1600
1423
  diagnostics.push({
1601
1424
  severity: "error",
@@ -1643,22 +1466,22 @@ var parseDictionaryIndex = (filePath, content, moduleClassName) => {
1643
1466
  let index;
1644
1467
  let modelFound = false;
1645
1468
  const visit = (node) => {
1646
- if (modelFound || !ts3.isCallExpression(node)) {
1647
- ts3.forEachChild(node, visit);
1469
+ if (modelFound || !ts6.isCallExpression(node)) {
1470
+ ts6.forEachChild(node, visit);
1648
1471
  return;
1649
1472
  }
1650
1473
  if (callExpressionName(node) !== "model") {
1651
- ts3.forEachChild(node, visit);
1474
+ ts6.forEachChild(node, visit);
1652
1475
  return;
1653
1476
  }
1654
1477
  const typeArgument = node.typeArguments?.[0];
1655
1478
  if (!typeArgument || typeArgument.getText(source) !== moduleClassName) {
1656
- ts3.forEachChild(node, visit);
1479
+ ts6.forEachChild(node, visit);
1657
1480
  return;
1658
1481
  }
1659
1482
  modelFound = true;
1660
- const callback = node.arguments.find((arg) => ts3.isArrowFunction(arg) || ts3.isFunctionExpression(arg));
1661
- if (!callback || !ts3.isArrowFunction(callback) && !ts3.isFunctionExpression(callback)) {
1483
+ const callback = node.arguments.find((arg) => ts6.isArrowFunction(arg) || ts6.isFunctionExpression(arg));
1484
+ if (!callback || !ts6.isArrowFunction(callback) && !ts6.isFunctionExpression(callback)) {
1662
1485
  diagnostics.push({
1663
1486
  severity: "error",
1664
1487
  code: "module-index-dictionary-builder-missing",
@@ -1684,7 +1507,7 @@ var parseDictionaryIndex = (filePath, content, moduleClassName) => {
1684
1507
  sourceSpan: spanFor(source, filePath, node)
1685
1508
  };
1686
1509
  };
1687
- ts3.forEachChild(source, visit);
1510
+ ts6.forEachChild(source, visit);
1688
1511
  return { index, diagnostics, modelFound };
1689
1512
  };
1690
1513
  var expectedFilesFor = (module) => {
@@ -1857,9 +1680,9 @@ var postApplyDiagnostic = (code, message, target, severity = "error") => ({
1857
1680
  });
1858
1681
  var sourceKindForPath = (filePath) => {
1859
1682
  if (filePath.endsWith(".tsx"))
1860
- return ts4.ScriptKind.TSX;
1683
+ return ts7.ScriptKind.TSX;
1861
1684
  if (filePath.endsWith(".ts"))
1862
- return ts4.ScriptKind.TS;
1685
+ return ts7.ScriptKind.TS;
1863
1686
  return null;
1864
1687
  };
1865
1688
  var checkPathCasing = async (workspace, filePath) => {
@@ -1887,7 +1710,7 @@ var checkTypeScriptSyntax = async (workspace, filePath) => {
1887
1710
  if (!scriptKind)
1888
1711
  return null;
1889
1712
  const content = await workspace.readFile(filePath);
1890
- const source = ts4.createSourceFile(filePath, content, ts4.ScriptTarget.Latest, true, scriptKind);
1713
+ const source = ts7.createSourceFile(filePath, content, ts7.ScriptTarget.Latest, true, scriptKind);
1891
1714
  const diagnostic = (source.parseDiagnostics ?? [])[0];
1892
1715
  if (!diagnostic)
1893
1716
  return null;
@@ -1895,7 +1718,7 @@ var checkTypeScriptSyntax = async (workspace, filePath) => {
1895
1718
  const location = position ? `:${position.line + 1}:${position.character + 1}` : "";
1896
1719
  return {
1897
1720
  code: "workflow-post-apply-syntax-error",
1898
- message: `Generated source has a TypeScript syntax error at ${filePath}${location}: ${ts4.flattenDiagnosticMessageText(diagnostic.messageText, " ")}`
1721
+ message: `Generated source has a TypeScript syntax error at ${filePath}${location}: ${ts7.flattenDiagnosticMessageText(diagnostic.messageText, " ")}`
1899
1722
  };
1900
1723
  };
1901
1724
  var checkChangedFile = async (workspace, file) => {
@@ -2052,9 +1875,9 @@ var resolveWorkflowSys = async (workspace, target) => {
2052
1875
  return null;
2053
1876
  const [apps, libs] = await workspace.getSyss();
2054
1877
  if (apps.includes(target))
2055
- return AppExecutor.from(workspace, target);
1878
+ return AppExecutor2.from(workspace, target);
2056
1879
  if (libs.includes(target))
2057
- return LibExecutor.from(workspace, target);
1880
+ return LibExecutor2.from(workspace, target);
2058
1881
  return null;
2059
1882
  };
2060
1883
  var targetMissing = (input = "app") => ({
@@ -2315,6 +2138,87 @@ class WorkflowExecutor {
2315
2138
  return report();
2316
2139
  }
2317
2140
  }
2141
+ // pkgs/@akanjs/devkit/workflow/fieldType.ts
2142
+ import ts8 from "typescript";
2143
+ var builtInFieldTypes = new Set(["String", "Boolean", "Date", "Map"]);
2144
+ var baseFieldTypes = new Set(["Int", "Float", "ID", "Any", "Binary", "ImageResult"]);
2145
+ var fieldTypeReference = /^\[*([A-Za-z_$][\w$]*)((?:\.[A-Za-z_$][\w$]*)*)\]*$/;
2146
+ var ensureBaseTypeImport = (content, typeName) => {
2147
+ const [, name = "", member] = fieldTypeReference.exec(typeName) ?? [];
2148
+ if (member || !baseFieldTypes.has(name))
2149
+ return content;
2150
+ return ensureBaseImport(content, name);
2151
+ };
2152
+ var valueNamesOf = (content) => {
2153
+ const names = new Set;
2154
+ for (const statement of sourceFileFor("source.ts", content).statements) {
2155
+ if (ts8.isImportDeclaration(statement)) {
2156
+ const clause = statement.importClause;
2157
+ if (!clause || clause.isTypeOnly)
2158
+ continue;
2159
+ if (clause.name)
2160
+ names.add(clause.name.text);
2161
+ const bindings = clause.namedBindings;
2162
+ if (bindings && ts8.isNamespaceImport(bindings))
2163
+ names.add(bindings.name.text);
2164
+ else
2165
+ for (const element of bindings?.elements ?? [])
2166
+ if (!element.isTypeOnly)
2167
+ names.add(element.name.text);
2168
+ } else if (ts8.isVariableStatement(statement)) {
2169
+ for (const declaration of statement.declarationList.declarations)
2170
+ if (ts8.isIdentifier(declaration.name))
2171
+ names.add(declaration.name.text);
2172
+ } else if ((ts8.isClassDeclaration(statement) || ts8.isEnumDeclaration(statement) || ts8.isFunctionDeclaration(statement)) && statement.name)
2173
+ names.add(statement.name.text);
2174
+ }
2175
+ return names;
2176
+ };
2177
+ var fieldTypeSource = async (sys, module, typeName, constantContent) => {
2178
+ const reference = fieldTypeReference.exec(typeName);
2179
+ if (!reference)
2180
+ return {
2181
+ diagnostic: {
2182
+ severity: "error",
2183
+ code: "primitive-field-type-unknown",
2184
+ input: "type",
2185
+ message: `Field type "${typeName}" is not a type name field() takes. Name one type, such as Address, or a list of one, such as [Address], then plan this again.`
2186
+ }
2187
+ };
2188
+ const [, name = "", member] = reference;
2189
+ if (builtInFieldTypes.has(name) || baseFieldTypes.has(name) || valueNamesOf(constantContent).has(name))
2190
+ return {};
2191
+ const [scalars, models] = await Promise.all([sys.getScalarModules(), sys.getDatabaseModules()]);
2192
+ const scalar = member ? undefined : scalars.find((scalarName) => moduleComponentName(scalarName) === name);
2193
+ if (scalar)
2194
+ return { import: { name, from: `../__scalar/${scalar}/${scalar}.constant` } };
2195
+ const model = member ? undefined : models.find((modelName) => moduleComponentName(modelName) === name);
2196
+ if (model)
2197
+ return { import: { name, from: `../${model}/${model}.constant` } };
2198
+ const root = getSysRoot(sys);
2199
+ const constantPath = `${root}/${moduleSourcePaths(module).constant}`;
2200
+ const named = (kind, names) => names.length ? `Its ${kind} are ${names.map(moduleComponentName).join(", ")}.` : `It has no ${kind}.`;
2201
+ return {
2202
+ diagnostic: {
2203
+ severity: "error",
2204
+ code: "primitive-field-type-unknown",
2205
+ input: "type",
2206
+ message: [
2207
+ `Field type "${typeName}" names ${name}, which is not a built-in or akanjs/base type, not imported by ${constantPath}, and not a scalar or model in ${root}.`,
2208
+ named("scalars", scalars),
2209
+ named("models", models),
2210
+ `Create the scalar with the create-scalar workflow first, or import ${name} into ${constantPath}, then plan this again.`
2211
+ ].join(" ")
2212
+ }
2213
+ };
2214
+ };
2215
+ var withFieldTypeImport = async (sys, module, typeName, content, diagnostics) => {
2216
+ const withBaseImport = ensureBaseTypeImport(content, typeName);
2217
+ const source = await fieldTypeSource(sys, module, typeName, withBaseImport);
2218
+ if (source.diagnostic)
2219
+ diagnostics.push(source.diagnostic);
2220
+ return source.import ? ensureNamedImport(withBaseImport, source.import.from, source.import.name) : withBaseImport;
2221
+ };
2318
2222
  // pkgs/@akanjs/devkit/workflow/guardCatalog.ts
2319
2223
  class GuardCatalog {
2320
2224
  static frameworkGuards = ["Public"];
@@ -2395,7 +2299,7 @@ class GuardCatalog {
2395
2299
  // pkgs/@akanjs/devkit/workflow/keyRename.ts
2396
2300
  import { readFile } from "fs/promises";
2397
2301
  import path2 from "path";
2398
- import ts5 from "typescript";
2302
+ import ts9 from "typescript";
2399
2303
  var indexedPath = /^(apps|libs)\/(?!(?:.*\/)?(?:node_modules|dist|\.akan)\/).*\.tsx?$/;
2400
2304
  var keyPattern = /^[a-z][A-Za-z0-9]*$/;
2401
2305
  var slashed = (fileName) => fileName.replace(/\\/g, "/");
@@ -2424,7 +2328,7 @@ class KeyRename {
2424
2328
  const sourceRelative = `${getSysRoot(sys)}/${family === "slice" ? paths.signal : paths.document}`;
2425
2329
  const sourcePath = slashed(path2.join(root, sourceRelative));
2426
2330
  const texts = new Map;
2427
- const index = new AkanIndex({ ts: ts5, root });
2331
+ const index = new AkanIndex({ ts: ts9, root });
2428
2332
  for (const relative of await workspace.getAllFiles("{apps,libs}/**/*.{ts,tsx}")) {
2429
2333
  if (!indexedPath.test(slashed(relative)))
2430
2334
  continue;
@@ -2645,6 +2549,138 @@ class MutationSource {
2645
2549
  }
2646
2550
  }
2647
2551
 
2552
+ // pkgs/@akanjs/devkit/workflow/serviceSource.ts
2553
+ import ts10 from "typescript";
2554
+ var hasClassMethod = (content, className, methodName) => {
2555
+ const node = findClassDeclaration(sourceFileFor("service.ts", content), className);
2556
+ return Boolean(node?.members.some((member) => ts10.isMethodDeclaration(member) && nodeName(member.name) === methodName));
2557
+ };
2558
+ var classMethodParameters = (content, className, methodName) => {
2559
+ const source = sourceFileFor("service.ts", content);
2560
+ const method = findClassDeclaration(source, className)?.members.find((member) => ts10.isMethodDeclaration(member) && nodeName(member.name) === methodName);
2561
+ return method?.parameters.map((parameter) => ({
2562
+ name: nodeName(parameter.name),
2563
+ optional: !!parameter.questionToken || !!parameter.initializer || !!parameter.dotDotDotToken
2564
+ })) ?? null;
2565
+ };
2566
+ var insertClassMethod = (content, className, methodBlock) => {
2567
+ const source = sourceFileFor("service.ts", content);
2568
+ const node = findClassDeclaration(source, className);
2569
+ if (!node)
2570
+ return null;
2571
+ const closeBrace = node.getEnd() - 1;
2572
+ if (content[closeBrace] !== "}")
2573
+ return null;
2574
+ const lead = content.slice(0, closeBrace).endsWith(`
2575
+ `) ? "" : `
2576
+ `;
2577
+ return spliceText(content, closeBrace, closeBrace, `${lead}${methodBlock}
2578
+ `);
2579
+ };
2580
+
2581
+ // pkgs/@akanjs/devkit/workflow/signalSource.ts
2582
+ import ts11 from "typescript";
2583
+ var arrowParamInnerRegion = (content, source, arrow) => {
2584
+ if (arrow.parameters.length > 0) {
2585
+ return {
2586
+ start: arrow.parameters[0].getStart(source),
2587
+ end: arrow.parameters[arrow.parameters.length - 1].getEnd()
2588
+ };
2589
+ }
2590
+ const open = content.indexOf("(", arrow.getStart(source));
2591
+ if (open < 0)
2592
+ return null;
2593
+ const close = content.indexOf(")", open);
2594
+ if (close < 0)
2595
+ return null;
2596
+ return { start: open + 1, end: close };
2597
+ };
2598
+ var factoryParamEdit = (content, source, arrow, plan) => {
2599
+ if (arrow.parameters.length > 1)
2600
+ return null;
2601
+ const region = arrowParamInnerRegion(content, source, arrow);
2602
+ if (!region)
2603
+ return null;
2604
+ if (arrow.parameters.length === 0) {
2605
+ return { ...region, text: plan.mode === "destructure" ? `{ ${plan.name} }` : plan.name };
2606
+ }
2607
+ const param = arrow.parameters[0];
2608
+ if (plan.mode === "positional")
2609
+ return nodeName(param.name) === plan.name ? "unchanged" : null;
2610
+ if (!ts11.isObjectBindingPattern(param.name))
2611
+ return null;
2612
+ const names = param.name.elements.map((element) => ts11.isIdentifier(element.name) ? element.name.text : null);
2613
+ if (names.some((name) => name === null))
2614
+ return null;
2615
+ if (names.includes(plan.name))
2616
+ return "unchanged";
2617
+ return {
2618
+ start: param.getStart(source),
2619
+ end: param.getEnd(),
2620
+ text: `{ ${[...names, plan.name].join(", ")} }`
2621
+ };
2622
+ };
2623
+ var factoryObjectOf = (source, className) => {
2624
+ const node = findClassDeclaration(source, className);
2625
+ const call = node ? firstHeritageCall(node) : null;
2626
+ const arrow = call ? factoryArrowOf(call) : null;
2627
+ const object = arrow ? firstObjectReturnedByArrow(arrow) : null;
2628
+ return arrow && object ? { arrow, object } : null;
2629
+ };
2630
+ var hasSignalFactoryEntry = (content, className, entryName) => {
2631
+ const located = factoryObjectOf(sourceFileFor("signal.ts", content), className);
2632
+ return Boolean(located?.object.properties.some((property) => propertyName(property) === entryName));
2633
+ };
2634
+ var insertSignalFactoryEntry = (content, className, entryName, entryLine, param) => {
2635
+ const source = sourceFileFor("signal.ts", content);
2636
+ const located = factoryObjectOf(source, className);
2637
+ if (!located)
2638
+ return null;
2639
+ const locator = locatedObject(source, located.object);
2640
+ if (locator.fields.some((field) => field.name === entryName))
2641
+ return content;
2642
+ const paramEdit = factoryParamEdit(content, source, located.arrow, param);
2643
+ if (paramEdit === null)
2644
+ return null;
2645
+ const withEntry = insertOrderedFieldLine(content, locator, entryName, entryLine, {
2646
+ fieldIndent: " ",
2647
+ closingIndent: ""
2648
+ });
2649
+ if (withEntry === content)
2650
+ return null;
2651
+ return paramEdit === "unchanged" ? withEntry : spliceText(withEntry, paramEdit.start, paramEdit.end, paramEdit.text);
2652
+ };
2653
+
2654
+ // pkgs/@akanjs/devkit/workflow/testSource.ts
2655
+ import ts12 from "typescript";
2656
+ var appendTopLevelTestCases = (content, describeTitle, render) => {
2657
+ const bunImport = findNamedImport(sourceFileFor("test.ts", content), "bun:test", { valueOnly: true });
2658
+ const itName = !bunImport?.names.includes("it") && bunImport?.names.includes("test") ? "test" : "it";
2659
+ const imported = ensureNamedImport(content, "bun:test", itName);
2660
+ const source = sourceFileFor("test.ts", imported);
2661
+ const body = source.statements.flatMap((statement) => {
2662
+ if (!ts12.isExpressionStatement(statement) || !ts12.isCallExpression(statement.expression))
2663
+ return [];
2664
+ if (expressionName(statement.expression.expression) !== "describe")
2665
+ return [];
2666
+ const callback = factoryArrowOf(statement.expression);
2667
+ return callback && ts12.isBlock(callback.body) ? [callback.body] : [];
2668
+ })[0];
2669
+ if (!body) {
2670
+ const block = [`describe(${JSON.stringify(describeTitle)}, () => {`, ...render(itName, " "), "});", ""];
2671
+ return `${ensureNamedImport(imported, "bun:test", "describe").trimEnd()}
2672
+
2673
+ ${block.join(`
2674
+ `)}`;
2675
+ }
2676
+ const firstStatement = body.statements[0];
2677
+ const indent = firstStatement ? lineIndentAt(imported, firstStatement.getStart(source)) : `${lineIndentAt(imported, body.getStart(source))} `;
2678
+ const insertAt = lineStartAt(imported, body.getEnd() - 1);
2679
+ return spliceText(imported, insertAt, insertAt, `${render(itName, indent).join(`
2680
+ `)}
2681
+ `);
2682
+ };
2683
+
2648
2684
  // pkgs/@akanjs/devkit/workflow/mutationScaffold.ts
2649
2685
  class MutationScaffold {
2650
2686
  static #documentMethods = new Set(["isModified", "refresh", "remove", "save", "set", "toJSON", "toObject"]);
@@ -3450,6 +3486,12 @@ var moduleNotDatabase = async (sys, spec, module) => {
3450
3486
  ].join(" ")
3451
3487
  };
3452
3488
  };
3489
+ var fieldTypeUnknown = async (sys, spec, module, type) => {
3490
+ if (spec.name !== "add-field" || !type || ["enum", "number", "numeric", "upload"].includes(type.toLowerCase()))
3491
+ return null;
3492
+ const constant = await sys.readFile(moduleSourcePaths(module).constant);
3493
+ return (await fieldTypeSource(sys, module, normalizeFieldType(type), constant)).diagnostic ?? null;
3494
+ };
3453
3495
  var workflowTargetDiagnostics = async (workspace, spec, inputs) => {
3454
3496
  const app = planString(inputs, "app");
3455
3497
  if (!app)
@@ -3470,7 +3512,7 @@ var workflowTargetDiagnostics = async (workspace, spec, inputs) => {
3470
3512
  const moduleSpec = spec.inputs.module;
3471
3513
  if (!module || !moduleSpec?.mustExist)
3472
3514
  return [];
3473
- const refused = await moduleMissing(workspace, sys, module) ?? await moduleNotDatabase(sys, spec, module);
3515
+ const refused = await moduleMissing(workspace, sys, module) ?? await moduleNotDatabase(sys, spec, module) ?? await fieldTypeUnknown(sys, spec, module, planString(inputs, "type"));
3474
3516
  return refused ? [refused] : [];
3475
3517
  };
3476
3518
  var inspectPlanTarget = async (workspace, spec, plan) => {
@@ -3839,4 +3881,76 @@ for (const candidate of toolingRolloutCandidates) {
3839
3881
  if (isRestrictedCandidate(candidate))
3840
3882
  restrictedCandidates.set(candidate.packageName, candidate);
3841
3883
  }
3842
- 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, KeyRename, MutationScaffold, listWorkflowSpecs, getWorkflowSpec, compactWorkflowInputs, createWorkflowPlan, workflowTargetDiagnostics, inspectWorkflowPlan, renderWorkflowList, renderWorkflowExplain, renderWorkflowPlan, renderWorkflowApply, renderWorkflowValidation, renderRepairReport, renderWorkflowRunArtifact, renderPrimitiveReport, toolingRolloutGate };
3884
+ // pkgs/@akanjs/devkit/workflow/primitiveReport.ts
3885
+ var sourceFile = (sys, path, action, reason) => ({
3886
+ path: `${getSysRoot(sys)}/${path}`,
3887
+ action,
3888
+ reason
3889
+ });
3890
+ var generatedFilesForSync = (sys, reason = "Generated files may change after sync.") => generatedFilePathsForTarget(getSysRoot(sys), reason);
3891
+ var validationCommandsForTarget = (target) => [
3892
+ { command: `akan verify ${target}`, reason: "Sync, lint, typecheck and build the target in one run." }
3893
+ ];
3894
+ var nextActionsForTarget = (target) => [
3895
+ { command: `akan verify ${target}`, reason: "Refresh generated files and validate the target in one run." }
3896
+ ];
3897
+ var createPrimitiveWriteReport = ({
3898
+ command,
3899
+ status,
3900
+ changedFiles = [],
3901
+ generatedFiles = [],
3902
+ validationCommands = [],
3903
+ diagnostics = [],
3904
+ nextActions = []
3905
+ }) => ({
3906
+ schemaVersion: 1,
3907
+ command,
3908
+ status: status ?? (diagnostics.some((diagnostic) => diagnostic.severity === "error") ? "failed" : "passed"),
3909
+ changedFiles,
3910
+ generatedFiles,
3911
+ validationCommands,
3912
+ diagnostics,
3913
+ nextActions
3914
+ });
3915
+ var createPassedPrimitiveReport = ({
3916
+ command,
3917
+ changedFiles,
3918
+ generatedFiles,
3919
+ target,
3920
+ nextActions
3921
+ }) => createPrimitiveWriteReport({
3922
+ command,
3923
+ changedFiles,
3924
+ generatedFiles: generatedFiles ?? [],
3925
+ validationCommands: validationCommandsForTarget(target),
3926
+ diagnostics: [],
3927
+ nextActions: nextActions ?? nextActionsForTarget(target)
3928
+ });
3929
+ var scalarChangedFiles = (sys, scalarName, files) => Object.values(files).map((file) => sourceFile(sys, `lib/__scalar/${scalarName}/${file.filename}`, "create", "Scalar source file was created."));
3930
+ // pkgs/@akanjs/devkit/workflow/templateSource.ts
3931
+ var insertTemplateField = ({
3932
+ content,
3933
+ moduleName,
3934
+ moduleClassName,
3935
+ fieldName,
3936
+ component
3937
+ }) => {
3938
+ if (content.includes(`l("${moduleName}.${fieldName}")`) || content.includes(`.${fieldName}`))
3939
+ return content;
3940
+ const layoutEndIndex = content.indexOf(" </Layout.Template>");
3941
+ if (layoutEndIndex < 0)
3942
+ return null;
3943
+ const formName = `${moduleName}Form`;
3944
+ if (!content.includes(`const ${formName} = st.use.${moduleName}Form();`))
3945
+ return null;
3946
+ const fieldSetter = `st.do.set${moduleComponentName(fieldName)}On${moduleClassName}`;
3947
+ const fieldBlock = ` <${component}
3948
+ label={l("${moduleName}.${fieldName}")}
3949
+ desc={l("${moduleName}.${fieldName}.desc")}
3950
+ value={${formName}.${fieldName}}
3951
+ onChange={${fieldSetter}}
3952
+ />
3953
+ `;
3954
+ return `${content.slice(0, layoutEndIndex)}${fieldBlock}${content.slice(layoutEndIndex)}`;
3955
+ };
3956
+ export { InteractionScaffold, jsonText, workflowStatus, compactDiagnostics, workflowPlanApproval, createWorkflowApplyReport, workflowCommandsForPlan, workflowPathsForPlan, workflowRunArtifactPath, writeWorkflowRunArtifact, workflowSyncDir, generatedFilePathsForTarget, writeGeneratedSyncState, readWorkflowRunArtifact, createWorkflowBaselineSummary, createWorkflowValidationRunReport, createDryRunWorkflowApplyReport, createRepairReport, hasSourceParseErrors, ensureNamedImport, ensureBaseImport, ensureEnumImport, ensureConstantTypeImport, viaBuilderParameterName, insertIntoObject, insertLightProjectionField, insertEnumClass, hasConstantInputField, bilingualLabelForField, bilingualDescriptionForField, insertDictionaryModelField, hasDictionaryModelField, insertDictionaryEnum, normalizeFieldType, coerceFieldDefault, fieldExpression, parseValues, moduleComponentName, moduleSourcePaths, buildAkanModuleContextIndex, addFieldUiPolicyForType, createWorkflowStepRegistry, WorkflowExecutor, withFieldTypeImport, KeyRename, hasClassMethod, insertClassMethod, hasSignalFactoryEntry, insertSignalFactoryEntry, MutationScaffold, listWorkflowSpecs, getWorkflowSpec, compactWorkflowInputs, createWorkflowPlan, workflowTargetDiagnostics, inspectWorkflowPlan, renderWorkflowList, renderWorkflowExplain, renderWorkflowPlan, renderWorkflowApply, renderWorkflowValidation, renderRepairReport, renderWorkflowRunArtifact, renderPrimitiveReport, toolingRolloutGate, sourceFile, generatedFilesForSync, validationCommandsForTarget, nextActionsForTarget, createPrimitiveWriteReport, createPassedPrimitiveReport, scalarChangedFiles, insertTemplateField };