@akanjs/cli 3.2.0-rc.8 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.build-stamp +2 -2
- package/CodeAgent-fx6088tv.js +11 -0
- package/{CodeTui-qstk5vpj.js → CodeTui-zee8atsr.js} +822 -666
- package/README.ko.md +7 -0
- package/README.md +7 -0
- package/TunnelShare-9ry4vh0y.js +18 -0
- package/agent.command-x65f2ags.js +61 -0
- package/akanCode.js +12 -12
- package/appExecutor-79azsb2w.js +11 -0
- package/{application.command-m4rq4wc2.js → application.command-azbd1pb2.js} +83 -37
- package/{applicationBuildRunner-df7rx3ra.js → applicationBuildRunner-trfxv3pd.js} +49 -18
- package/buildBatch.proc.js +25 -11
- package/{cloud.command-a0gy0qq2.js → cloud.command-gapp4634.js} +33 -29
- package/cloud.script-3b401efv.js +35 -0
- package/{code.command-5rsdqw8s.js → code.command-5smx61yf.js} +13 -9
- package/context.command-ym5jbkny.js +64 -0
- package/context.runner-kctbfsde.js +34 -0
- package/{dependencyScanner-78sq8m4q.js → dependencyScanner-ge10gb52.js} +2 -2
- package/{devTui-h77zrjv5.js → devTui-rf374y2w.js} +1 -1
- package/{fileSys-zpvt5gtf.js → fileSys-q22646yc.js} +1 -1
- package/{guideline.command-mffxknbr.js → guideline.command-zwypaqsh.js} +9 -5
- package/guidelines/agentRule/agentRule.instruction.md +25 -9
- package/guidelines/akanApi/akanApi.instruction.md +6 -4
- package/guidelines/conventions/core.md +23 -5
- package/guidelines/conventions/rules/app.md +4 -1
- package/guidelines/conventions/rules/page.md +5 -4
- package/guidelines/conventions/rules/ts.md +3 -3
- package/guidelines/errorCodes/errorCodes.instruction.md +165 -0
- package/guidelines/fieldRule/fieldRule.instruction.md +2 -1
- package/guidelines/mcpRule/mcpRule.instruction.md +225 -5
- package/guidelines/pageRule/pageRule.instruction.md +10 -1
- package/guidelines/queryRule/queryRule.instruction.md +3 -1
- package/guidelines/runtimeRule/runtimeRule.instruction.md +14 -8
- package/guidelines/transportRule/transportRule.instruction.md +31 -1
- package/incrementalBuilder.proc.js +577 -411
- package/{index-w15mg3km.js → index-0dm25wvf.js} +1 -1
- package/{index-0gg15zwa.js → index-0s7w2085.js} +6 -6
- package/{index-hj6w4ka1.js → index-1p81ecbz.js} +1 -1
- package/{index-swwjakt0.js → index-275a4r3n.js} +11 -11
- package/{index-j6gc8n14.js → index-2jmvfa62.js} +11 -9
- package/{index-qd7xn2bk.js → index-2ny1e95c.js} +2 -2
- package/{index-exn38bzx.js → index-2yn3r67f.js} +116 -54
- package/{index-34792nh7.js → index-3txdtztz.js} +1 -1
- package/{index-28x1aszt.js → index-41a03gkj.js} +149 -53
- package/{index-2mf1aen9.js → index-4ss4gkv3.js} +2 -2
- package/{index-an76bdrv.js → index-612fdtbk.js} +1 -1
- package/{index-5radqwn2.js → index-67sd09ag.js} +12 -12
- package/{index-0hbtve0a.js → index-6dzjer7p.js} +32 -28
- package/{index-3ghdb7p5.js → index-71y6176j.js} +2777 -3676
- package/{index-xyn02k0w.js → index-78y75t0a.js} +662 -433
- package/index-7wf8snar.js +80 -0
- package/{index-skmtj8rm.js → index-8jtqfye2.js} +27 -10
- package/{index-2mrn1mrg.js → index-9f3reh2y.js} +1 -1
- package/{index-nmvhjn8c.js → index-9wh04mqy.js} +93 -82
- package/{index-xvk2a75m.js → index-a860mx0m.js} +3 -3
- package/{index-5zwr4n6k.js → index-baccvws5.js} +65 -8
- package/{index-yf9wc28h.js → index-bejy9zyc.js} +1 -1
- package/{index-bns3wcpc.js → index-by2tvsq6.js} +1 -1
- package/{index-r0a604h4.js → index-c669pbyb.js} +5 -4
- package/{index-x40bdsca.js → index-dadwp2aw.js} +33 -98
- package/{index-vm0dn0mt.js → index-dmcpetwe.js} +200 -138
- package/{index-43f4h4cm.js → index-ebn9kgea.js} +6 -6
- package/{index-hqv34wzq.js → index-gt8phqpt.js} +10 -10
- package/{index-yckz5t8b.js → index-h901f24n.js} +516 -434
- package/{index-j3v29pq7.js → index-j0wr4e32.js} +219 -175
- package/{index-gcx48get.js → index-j592zfqc.js} +2 -2
- package/{index-grxs6fts.js → index-j6jjmn2r.js} +57 -31
- package/{index-w8yasvpc.js → index-jek2re5k.js} +2136 -2175
- package/{index-ny2k80mv.js → index-jf4vk1s0.js} +9 -2
- package/{index-gxav1bjz.js → index-k6vwww45.js} +9 -9
- package/{index-99qvtff2.js → index-kfvjzk8r.js} +5 -5
- package/{index-j6eeh5d7.js → index-knpm8sdm.js} +5 -5
- package/{index-2r9ff9qm.js → index-nc3br31y.js} +2 -2
- package/{index-35j83zkd.js → index-p5zh7pmc.js} +2 -2
- package/{index-cmg5ngqa.js → index-p7beqww9.js} +2 -2
- package/{index-b4qq3rq0.js → index-rwgqba9p.js} +1 -1
- package/{index-rfzp4pqs.js → index-s885g0jj.js} +3 -3
- package/{index-9p260r4e.js → index-trffs83s.js} +538 -250
- package/{index-k92x3vne.js → index-v7ajmsh3.js} +1 -1
- package/index-w1zexzpx.js +127 -0
- package/{index-h7hehkw6.js → index-xczjdng6.js} +3 -1
- package/{index-39jz41jb.js → index-xs9a3ddt.js} +3 -3
- package/{index-rp4yf32g.js → index-xwwex8rf.js} +36 -29
- package/{index-ra9fvn7s.js → index-ybcb9wc8.js} +74 -38
- package/index-z92zm3wd.js +788 -0
- package/{index-j9790rhk.js → index-z96ks033.js} +1509 -1121
- package/index-zfnz878d.js +30 -0
- package/{index-2vgv7fs7.js → index-zmd9xxgd.js} +727 -693
- package/{index-ygdbn9jn.js → index-zyb0ebm4.js} +1 -1
- package/index.js +28 -24
- package/libExecutor-jc6f8hm6.js +10 -0
- package/{library.command-bmd7zc5m.js → library.command-nxvesvhb.js} +12 -5
- package/{localRegistry.command-y6en1599.js → localRegistry.command-xz62e4ng.js} +29 -24
- package/{module.command-7exfffqw.js → module.command-aaws9byg.js} +11 -7
- package/{package.command-adskw2rj.js → package.command-j7hv26p0.js} +14 -10
- package/package.json +8 -8
- package/{page.command-dw01272p.js → page.command-7yffs7n9.js} +8 -4
- package/{pipeline.command-0b1r3y5r.js → pipeline.command-7yk0zcng.js} +15 -9
- package/pkgExecutor-arxmvx4t.js +10 -0
- package/{primitive.command-byw6vc04.js → primitive.command-7a1pt715.js} +12 -8
- package/{projectTypecheck-kkrpq60a.js → projectTypecheck-f4qhbecd.js} +1 -1
- package/{prompter-qrwx1p17.js → prompter-qyggfhqd.js} +2 -2
- package/{quality.command-6rqnhzct.js → quality.command-c6mvrjh1.js} +25 -16
- package/{recipeScanner-4b69ybe0.js → recipeScanner-rrx69awy.js} +1 -1
- package/{repair.command-rw5zymak.js → repair.command-093adzt9.js} +12 -8
- package/{routeSourceValidator-4h947v7c.js → routeSourceValidator-8n6j1vn7.js} +4 -2
- package/{scalar.command-2dyp9nh9.js → scalar.command-2ex84spb.js} +10 -6
- package/skills/akan-debug/SKILL.md +8 -5
- package/skills/akan-err/SKILL.md +7 -0
- package/skills/akan-mcp/SKILL.md +19 -1
- package/skills/akan-scaffold/SKILL.md +1 -1
- package/skills/akan-validate/SKILL.md +3 -3
- package/{subspace.command-111ynwv1.js → subspace.command-4n4n4jpv.js} +32 -24
- package/templates/app/page/_layout.tsx +13 -0
- package/templates/app/page/styles.css.template +40 -0
- package/templates/appSample/page/_index.tsx +9 -9
- package/templates/appSample/page/_layout.tsx +1 -0
- package/templates/appSample/page/styles.css.template +40 -5
- package/templates/appSample/ui/Recipe/jellyButton.ts +1 -1
- package/templates/biomeForm.ts +1 -1
- package/templates/env/_env.server.type.ts +1 -1
- package/templates/facetIndex/index.ts +2 -37
- package/templates/lib/sig.ts +0 -4
- package/templates/lib/useClient.ts +1 -1
- package/templates/workspaceRoot/.devcontainer/devcontainer.json.template +1 -1
- package/templates/workspaceRoot/AGENTS.md.template +2 -1
- package/templates/workspaceRoot/README.ts +4 -2
- package/{tunnel.command-2gcpfbdj.js → tunnel.command-f7ep1qfa.js} +17 -13
- package/{typeChecker-s640r6c0.js → typeChecker-7jt6abrs.js} +1 -1
- package/typecheck.proc.js +3 -2
- package/{verify.command-djgs86ma.js → verify.command-zrkxnvct.js} +21 -17
- package/{workflow.command-n0k2mxr5.js → workflow.command-ks16jegk.js} +21 -14
- package/{workspace.command-fh1qwxfx.js → workspace.command-ahhfpaag.js} +60 -54
- package/CodeAgent-x2p3a3e0.js +0 -11
- package/TunnelShare-c4xsfzg5.js +0 -15
- package/agent.command-9et2e27p.js +0 -52
- package/cloud.script-xze4zh7n.js +0 -31
- package/context.command-rk1dwrg4.js +0 -57
- package/context.runner-83ky5m1b.js +0 -30
- /package/templates/{appSample → app}/public/fonts/Pretendard-Bold.woff2 +0 -0
- /package/templates/{appSample → app}/public/fonts/Pretendard-Medium.woff2 +0 -0
- /package/templates/{appSample → app}/public/fonts/Pretendard-Regular.woff2 +0 -0
- /package/templates/{appSample → app}/public/fonts/Pretendard-SemiBold.woff2 +0 -0
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
AppExecutor2
|
|
4
|
+
} from "./index-z92zm3wd.js";
|
|
5
|
+
import {
|
|
6
|
+
LibExecutor2
|
|
7
|
+
} from "./index-zfnz878d.js";
|
|
6
8
|
import {
|
|
7
9
|
createAst,
|
|
8
10
|
AkanIndex
|
|
9
|
-
} from "./index-
|
|
11
|
+
} from "./index-trffs83s.js";
|
|
10
12
|
import {
|
|
11
13
|
sysNamePattern,
|
|
12
14
|
identifierPattern
|
|
13
15
|
} from "./index-va90m8nd.js";
|
|
14
16
|
import {
|
|
15
17
|
camelToKebabCase
|
|
16
|
-
} from "./index-
|
|
18
|
+
} from "./index-2yn3r67f.js";
|
|
17
19
|
|
|
18
20
|
// pkgs/@akanjs/devkit/workflow/artifacts.ts
|
|
19
21
|
import { capitalize as capitalize2 } from "akanjs/common";
|
|
@@ -529,15 +531,12 @@ var createRepairReport = ({
|
|
|
529
531
|
});
|
|
530
532
|
// pkgs/@akanjs/devkit/workflow/executor.ts
|
|
531
533
|
import { capitalize as capitalize3 } from "akanjs/common";
|
|
532
|
-
import
|
|
534
|
+
import ts7 from "typescript";
|
|
533
535
|
|
|
534
|
-
// pkgs/@akanjs/devkit/workflow/
|
|
535
|
-
import
|
|
536
|
-
import path from "path";
|
|
537
|
-
import ts3 from "typescript";
|
|
536
|
+
// pkgs/@akanjs/devkit/workflow/constantSource.ts
|
|
537
|
+
import ts4 from "typescript";
|
|
538
538
|
|
|
539
|
-
// pkgs/@akanjs/devkit/workflow/
|
|
540
|
-
import { lowerlize as lowerlize2 } from "akanjs/common";
|
|
539
|
+
// pkgs/@akanjs/devkit/workflow/fieldOrder.ts
|
|
541
540
|
import ts2 from "typescript";
|
|
542
541
|
|
|
543
542
|
// pkgs/@akanjs/devkit/workflow/sourceAst.ts
|
|
@@ -551,130 +550,121 @@ var {
|
|
|
551
550
|
firstObjectReturnedByArrow,
|
|
552
551
|
heritageCall
|
|
553
552
|
} = createAst(ts);
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
var
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
abstract: `lib/${moduleName}/${moduleName}.abstract.md`,
|
|
567
|
-
constant: `lib/${moduleName}/${moduleName}.constant.ts`,
|
|
568
|
-
dictionary: `lib/${moduleName}/${moduleName}.dictionary.ts`,
|
|
569
|
-
document: `lib/${moduleName}/${moduleName}.document.ts`,
|
|
570
|
-
service: `lib/${moduleName}/${moduleName}.service.ts`,
|
|
571
|
-
signal: `lib/${moduleName}/${moduleName}.signal.ts`,
|
|
572
|
-
store: `lib/${moduleName}/${moduleName}.store.ts`,
|
|
573
|
-
template: `lib/${moduleName}/${componentName}.Template.tsx`,
|
|
574
|
-
unit: `lib/${moduleName}/${componentName}.Unit.tsx`,
|
|
575
|
-
util: `lib/${moduleName}/${componentName}.Util.tsx`,
|
|
576
|
-
view: `lib/${moduleName}/${componentName}.View.tsx`,
|
|
577
|
-
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);
|
|
578
565
|
};
|
|
566
|
+
ts.forEachChild(source, visit);
|
|
567
|
+
return found;
|
|
579
568
|
};
|
|
580
|
-
var
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
];
|
|
584
|
-
var nextActionsForTarget = (target) => [
|
|
585
|
-
{ command: `akan verify ${target}`, reason: "Refresh generated files and validate the target in one run." }
|
|
586
|
-
];
|
|
587
|
-
var createPrimitiveWriteReport = ({
|
|
588
|
-
command,
|
|
589
|
-
status,
|
|
590
|
-
changedFiles = [],
|
|
591
|
-
generatedFiles = [],
|
|
592
|
-
validationCommands = [],
|
|
593
|
-
diagnostics = [],
|
|
594
|
-
nextActions = []
|
|
595
|
-
}) => ({
|
|
596
|
-
schemaVersion: 1,
|
|
597
|
-
command,
|
|
598
|
-
status: status ?? (diagnostics.some((diagnostic) => diagnostic.severity === "error") ? "failed" : "passed"),
|
|
599
|
-
changedFiles,
|
|
600
|
-
generatedFiles,
|
|
601
|
-
validationCommands,
|
|
602
|
-
diagnostics,
|
|
603
|
-
nextActions
|
|
604
|
-
});
|
|
605
|
-
var createPassedPrimitiveReport = ({
|
|
606
|
-
command,
|
|
607
|
-
changedFiles,
|
|
608
|
-
generatedFiles,
|
|
609
|
-
target,
|
|
610
|
-
nextActions
|
|
611
|
-
}) => createPrimitiveWriteReport({
|
|
612
|
-
command,
|
|
613
|
-
changedFiles,
|
|
614
|
-
generatedFiles: generatedFiles ?? [],
|
|
615
|
-
validationCommands: validationCommandsForTarget(target),
|
|
616
|
-
diagnostics: [],
|
|
617
|
-
nextActions: nextActions ?? nextActionsForTarget(target)
|
|
618
|
-
});
|
|
619
|
-
var scalarChangedFiles = (sys, scalarName, files) => Object.values(files).map((file) => sourceFile(sys, `lib/__scalar/${scalarName}/${file.filename}`, "create", "Scalar source file was created."));
|
|
620
|
-
var titleize = (value) => value.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[-_]+/g, " ").replace(/\b\w/g, (char) => char.toUpperCase());
|
|
621
|
-
var koLabels = {
|
|
622
|
-
amount: "\uAE08\uC561",
|
|
623
|
-
budget: "\uC608\uC0B0",
|
|
624
|
-
category: "\uCE74\uD14C\uACE0\uB9AC",
|
|
625
|
-
content: "\uB0B4\uC6A9",
|
|
626
|
-
count: "\uAC1C\uC218",
|
|
627
|
-
createdAt: "\uC0DD\uC131\uC77C",
|
|
628
|
-
date: "\uB0A0\uC9DC",
|
|
629
|
-
description: "\uC124\uBA85",
|
|
630
|
-
due: "\uB9C8\uAC10\uC77C",
|
|
631
|
-
dueAt: "\uB9C8\uAC10\uC77C",
|
|
632
|
-
email: "\uC774\uBA54\uC77C",
|
|
633
|
-
enabled: "\uD65C\uC131\uD654",
|
|
634
|
-
endAt: "\uC885\uB8CC\uC77C",
|
|
635
|
-
id: "ID",
|
|
636
|
-
name: "\uC774\uB984",
|
|
637
|
-
owner: "\uB2F4\uB2F9\uC790",
|
|
638
|
-
priority: "\uC6B0\uC120\uC21C\uC704",
|
|
639
|
-
project: "\uD504\uB85C\uC81D\uD2B8",
|
|
640
|
-
rating: "\uD3C9\uC810",
|
|
641
|
-
startAt: "\uC2DC\uC791\uC77C",
|
|
642
|
-
status: "\uC0C1\uD0DC",
|
|
643
|
-
title: "\uC81C\uBAA9",
|
|
644
|
-
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;
|
|
645
572
|
};
|
|
646
|
-
var
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
return koLabels[fieldName];
|
|
650
|
-
const words = splitFieldWords(fieldName);
|
|
651
|
-
const translated = words.map((word) => koLabels[word] ?? koLabels[lowerlize2(word)] ?? null);
|
|
652
|
-
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;
|
|
653
576
|
};
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
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;
|
|
657
586
|
};
|
|
658
|
-
var
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
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;
|
|
664
622
|
};
|
|
665
|
-
var
|
|
666
|
-
const
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
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
|
+
`);
|
|
677
664
|
};
|
|
665
|
+
|
|
666
|
+
// pkgs/@akanjs/devkit/workflow/sourceImports.ts
|
|
667
|
+
import ts3 from "typescript";
|
|
678
668
|
var importOrder = (a, b) => {
|
|
679
669
|
const [lowerA, lowerB] = [a.toLowerCase(), b.toLowerCase()];
|
|
680
670
|
if (lowerA !== lowerB)
|
|
@@ -696,7 +686,7 @@ var ensureImportDeclaration = (content, moduleSpecifier, clause) => {
|
|
|
696
686
|
if (content.includes(line))
|
|
697
687
|
return content;
|
|
698
688
|
const source = sourceFileFor("source.ts", content);
|
|
699
|
-
const imports = source.statements.filter((statement) =>
|
|
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() }] : []);
|
|
700
690
|
const isRelative = (specifier) => specifier.startsWith(".");
|
|
701
691
|
const peers = imports.filter((entry) => isRelative(entry.specifier) === isRelative(moduleSpecifier));
|
|
702
692
|
const before = peers.find((entry) => importOrder(entry.specifier, moduleSpecifier) > 0);
|
|
@@ -719,244 +709,67 @@ ${line}
|
|
|
719
709
|
`);
|
|
720
710
|
};
|
|
721
711
|
var ensureBaseImport = (content, name) => ensureNamedImport(content, "akanjs/base", name);
|
|
722
|
-
var
|
|
723
|
-
|
|
724
|
-
if (!
|
|
725
|
-
|
|
726
|
-
if (
|
|
727
|
-
|
|
728
|
-
|
|
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
729
|
}
|
|
730
|
-
|
|
731
|
-
return null;
|
|
732
|
-
const trimmed = rawDefault.trim();
|
|
733
|
-
if (!trimmed || !Number.isFinite(Number(trimmed)))
|
|
734
|
-
return null;
|
|
735
|
-
if (typeName === "Int" && !/^-?\d+$/.test(trimmed))
|
|
736
|
-
return null;
|
|
737
|
-
return trimmed;
|
|
730
|
+
return null;
|
|
738
731
|
};
|
|
739
|
-
var
|
|
740
|
-
if (
|
|
741
|
-
return
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
};
|
|
747
|
-
var dateDefault = (rawDefault) => {
|
|
748
|
-
if (typeof rawDefault === "number" && Number.isFinite(rawDefault))
|
|
749
|
-
return `() => dayjs(${rawDefault})`;
|
|
750
|
-
if (typeof rawDefault !== "string")
|
|
751
|
-
return null;
|
|
752
|
-
const trimmed = rawDefault.trim();
|
|
753
|
-
if (!trimmed)
|
|
754
|
-
return null;
|
|
755
|
-
if (trimmed === "now")
|
|
756
|
-
return "() => dayjs()";
|
|
757
|
-
if (!Number.isNaN(Date.parse(trimmed)))
|
|
758
|
-
return `() => dayjs(${JSON.stringify(trimmed)})`;
|
|
759
|
-
return null;
|
|
760
|
-
};
|
|
761
|
-
var coerceFieldDefault = (typeName, defaultValue, options = {}) => {
|
|
762
|
-
const normalizedType = typeName.toLowerCase() === "enum" ? "enum" : normalizeFieldType(typeName);
|
|
763
|
-
if (defaultValue === undefined || defaultValue === null || defaultValue === "") {
|
|
764
|
-
return { expression: null, normalized: false, normalizedType };
|
|
765
|
-
}
|
|
766
|
-
if (normalizedType === "Int" || normalizedType === "Float") {
|
|
767
|
-
const expression = numericDefault(normalizedType, defaultValue);
|
|
768
|
-
if (expression !== null)
|
|
769
|
-
return { expression, normalized: typeof defaultValue === "string", normalizedType };
|
|
770
|
-
return {
|
|
771
|
-
expression: null,
|
|
772
|
-
normalized: false,
|
|
773
|
-
normalizedType,
|
|
774
|
-
diagnostic: {
|
|
775
|
-
severity: "error",
|
|
776
|
-
code: "primitive-default-value-invalid",
|
|
777
|
-
input: "default",
|
|
778
|
-
failureScope: "source-change",
|
|
779
|
-
message: `Default value for ${normalizedType} must be a numeric literal. Received: ${JSON.stringify(defaultValue)}.`
|
|
780
|
-
}
|
|
781
|
-
};
|
|
782
|
-
}
|
|
783
|
-
if (normalizedType === "Boolean") {
|
|
784
|
-
const expression = booleanDefault(defaultValue);
|
|
785
|
-
if (expression !== null)
|
|
786
|
-
return { expression, normalized: typeof defaultValue === "string", normalizedType };
|
|
787
|
-
return {
|
|
788
|
-
expression: null,
|
|
789
|
-
normalized: false,
|
|
790
|
-
normalizedType,
|
|
791
|
-
diagnostic: {
|
|
792
|
-
severity: "error",
|
|
793
|
-
code: "primitive-default-value-invalid",
|
|
794
|
-
input: "default",
|
|
795
|
-
failureScope: "source-change",
|
|
796
|
-
message: `Default value for Boolean must be true or false. Received: ${JSON.stringify(defaultValue)}.`
|
|
797
|
-
}
|
|
798
|
-
};
|
|
799
|
-
}
|
|
800
|
-
if (normalizedType === "Date") {
|
|
801
|
-
const expression = dateDefault(defaultValue);
|
|
802
|
-
if (expression !== null)
|
|
803
|
-
return { expression, normalized: true, normalizedType };
|
|
804
|
-
return {
|
|
805
|
-
expression: null,
|
|
806
|
-
normalized: false,
|
|
807
|
-
normalizedType,
|
|
808
|
-
diagnostic: {
|
|
809
|
-
severity: "error",
|
|
810
|
-
code: "primitive-default-value-invalid",
|
|
811
|
-
input: "default",
|
|
812
|
-
failureScope: "source-change",
|
|
813
|
-
message: `Default value for Date must be "now", a timestamp, or a parseable date string. Received: ${JSON.stringify(defaultValue)}.`
|
|
814
|
-
}
|
|
815
|
-
};
|
|
816
|
-
}
|
|
817
|
-
if (normalizedType === "enum") {
|
|
818
|
-
if (typeof defaultValue === "string" && options.enumValues?.includes(defaultValue)) {
|
|
819
|
-
return { expression: JSON.stringify(defaultValue), normalized: false, normalizedType };
|
|
820
|
-
}
|
|
821
|
-
return {
|
|
822
|
-
expression: null,
|
|
823
|
-
normalized: false,
|
|
824
|
-
normalizedType,
|
|
825
|
-
diagnostic: {
|
|
826
|
-
severity: "error",
|
|
827
|
-
code: "primitive-default-value-invalid",
|
|
828
|
-
input: "default",
|
|
829
|
-
failureScope: "source-change",
|
|
830
|
-
message: `Default value for enum must be one of: ${(options.enumValues ?? []).join(", ")}. Received: ${JSON.stringify(defaultValue)}.`
|
|
831
|
-
}
|
|
832
|
-
};
|
|
732
|
+
var ensureEnumImport = (content) => {
|
|
733
|
+
if (content.includes("enumOf"))
|
|
734
|
+
return content;
|
|
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";`);
|
|
833
739
|
}
|
|
834
|
-
return {
|
|
835
|
-
|
|
836
|
-
normalized: typeof defaultValue !== "string",
|
|
837
|
-
normalizedType
|
|
838
|
-
};
|
|
839
|
-
};
|
|
840
|
-
var fieldExpression = (typeName, defaultValue, options = {}) => {
|
|
841
|
-
const typeExpression = normalizeFieldType(typeName);
|
|
842
|
-
const defaultExpression = coerceFieldDefault(options.enumValues ? "enum" : typeExpression, defaultValue, options).expression;
|
|
843
|
-
const defaultOption = defaultExpression ? `, { default: ${defaultExpression} }` : "";
|
|
844
|
-
return `${options.builderName ?? "field"}(${typeExpression}${defaultOption})`;
|
|
740
|
+
return `import { enumOf } from "akanjs/base";
|
|
741
|
+
${content}`;
|
|
845
742
|
};
|
|
846
|
-
var
|
|
847
|
-
"
|
|
848
|
-
|
|
849
|
-
"
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
"
|
|
856
|
-
|
|
857
|
-
"createdAt",
|
|
858
|
-
"updatedAt"
|
|
859
|
-
];
|
|
860
|
-
var hasParseDiagnostics = (source) => (source.parseDiagnostics ?? []).length > 0;
|
|
861
|
-
var spliceText = (content, start, end, replacement) => `${content.slice(0, start)}${replacement}${content.slice(end)}`;
|
|
862
|
-
var lineStartAt = (content, position) => content.lastIndexOf(`
|
|
863
|
-
`, Math.max(0, position - 1)) + 1;
|
|
864
|
-
var lineEndAt = (content, position) => {
|
|
865
|
-
const end = content.indexOf(`
|
|
866
|
-
`, position);
|
|
867
|
-
return end < 0 ? content.length : end + 1;
|
|
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}";`);
|
|
751
|
+
}
|
|
752
|
+
return `import type { ${typeName} } from "${constantPath}";
|
|
753
|
+
${content}`;
|
|
868
754
|
};
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
objectStart: objectLiteral.getStart(source),
|
|
872
|
-
objectEnd: objectLiteral.getEnd(),
|
|
873
|
-
fields: objectLiteral.properties.map((property) => {
|
|
874
|
-
const name = propertyName(property);
|
|
875
|
-
if (!name)
|
|
876
|
-
return null;
|
|
877
|
-
return {
|
|
878
|
-
name,
|
|
879
|
-
start: property.getStart(source),
|
|
880
|
-
fullStart: property.getFullStart(),
|
|
881
|
-
end: property.getEnd()
|
|
882
|
-
};
|
|
883
|
-
}).filter((field) => field !== null)
|
|
884
|
-
});
|
|
755
|
+
|
|
756
|
+
// pkgs/@akanjs/devkit/workflow/constantSource.ts
|
|
885
757
|
var findConstantInputObject = (source, className) => {
|
|
886
758
|
let locator = null;
|
|
887
759
|
const visit = (node) => {
|
|
888
760
|
if (locator)
|
|
889
761
|
return;
|
|
890
|
-
if (!
|
|
891
|
-
|
|
762
|
+
if (!ts4.isClassDeclaration(node) || node.name?.text !== className) {
|
|
763
|
+
ts4.forEachChild(node, visit);
|
|
892
764
|
return;
|
|
893
765
|
}
|
|
894
766
|
const viaCall = heritageCall(node);
|
|
895
|
-
const callback = viaCall?.arguments.find((arg) =>
|
|
767
|
+
const callback = viaCall?.arguments.find((arg) => ts4.isArrowFunction(arg) || ts4.isFunctionExpression(arg));
|
|
896
768
|
const objectLiteral = callback ? firstObjectReturnedByArrow(callback) : null;
|
|
897
769
|
if (objectLiteral)
|
|
898
770
|
locator = locatedObject(source, objectLiteral);
|
|
899
771
|
};
|
|
900
|
-
|
|
901
|
-
return locator;
|
|
902
|
-
};
|
|
903
|
-
var chainMethodsForCall = (node) => {
|
|
904
|
-
if (ts2.isAsExpression(node) || ts2.isParenthesizedExpression(node))
|
|
905
|
-
return chainMethodsForCall(node.expression);
|
|
906
|
-
if (!ts2.isCallExpression(node))
|
|
907
|
-
return [];
|
|
908
|
-
if (ts2.isPropertyAccessExpression(node.expression)) {
|
|
909
|
-
return [...chainMethodsForCall(node.expression.expression), node.expression.name.text];
|
|
910
|
-
}
|
|
911
|
-
const name = expressionName(node.expression);
|
|
912
|
-
return name ? [name] : [];
|
|
913
|
-
};
|
|
914
|
-
var outermostFluentCall = (node) => {
|
|
915
|
-
let current = node;
|
|
916
|
-
while (ts2.isPropertyAccessExpression(current.parent) && current.parent.expression === current && ts2.isCallExpression(current.parent.parent) && current.parent.parent.expression === current.parent) {
|
|
917
|
-
current = current.parent.parent;
|
|
918
|
-
}
|
|
919
|
-
return current;
|
|
920
|
-
};
|
|
921
|
-
var protectedDictionaryChainOrder = ["model", "slice", "enum", "error", "translate"];
|
|
922
|
-
var dictionaryChainOrderValid = (chainMethods) => {
|
|
923
|
-
const protectedOrder = new Map(protectedDictionaryChainOrder.map((method, index) => [method, index]));
|
|
924
|
-
let lastOrder = -1;
|
|
925
|
-
for (const method of chainMethods) {
|
|
926
|
-
const order = protectedOrder.get(method);
|
|
927
|
-
if (order === undefined)
|
|
928
|
-
continue;
|
|
929
|
-
if (order < lastOrder)
|
|
930
|
-
return false;
|
|
931
|
-
lastOrder = order;
|
|
932
|
-
}
|
|
933
|
-
return true;
|
|
934
|
-
};
|
|
935
|
-
var findDictionaryModelObject = (source, moduleClassName) => findDictionaryStageObject(source, "model", moduleClassName);
|
|
936
|
-
var findDictionaryStageObject = (source, stage, typeName) => {
|
|
937
|
-
let locator = null;
|
|
938
|
-
const visit = (node) => {
|
|
939
|
-
if (locator)
|
|
940
|
-
return;
|
|
941
|
-
if (!ts2.isCallExpression(node) || callExpressionName(node) !== stage) {
|
|
942
|
-
ts2.forEachChild(node, visit);
|
|
943
|
-
return;
|
|
944
|
-
}
|
|
945
|
-
const typeArgument = node.typeArguments?.[0];
|
|
946
|
-
if (!typeArgument || typeArgument.getText(source) !== typeName) {
|
|
947
|
-
ts2.forEachChild(node, visit);
|
|
948
|
-
return;
|
|
949
|
-
}
|
|
950
|
-
const callback = node.arguments.find((arg) => ts2.isArrowFunction(arg) || ts2.isFunctionExpression(arg));
|
|
951
|
-
const objectLiteral = callback ? firstObjectReturnedByArrow(callback) : null;
|
|
952
|
-
if (objectLiteral) {
|
|
953
|
-
locator = {
|
|
954
|
-
...locatedObject(source, objectLiteral),
|
|
955
|
-
chainMethods: chainMethodsForCall(outermostFluentCall(node))
|
|
956
|
-
};
|
|
957
|
-
}
|
|
958
|
-
};
|
|
959
|
-
ts2.forEachChild(source, visit);
|
|
772
|
+
ts4.forEachChild(source, visit);
|
|
960
773
|
return locator;
|
|
961
774
|
};
|
|
962
775
|
var findLightProjectionArray = (source, moduleClassName) => {
|
|
@@ -964,118 +777,52 @@ var findLightProjectionArray = (source, moduleClassName) => {
|
|
|
964
777
|
const visit = (node) => {
|
|
965
778
|
if (locator)
|
|
966
779
|
return;
|
|
967
|
-
if (!
|
|
968
|
-
|
|
780
|
+
if (!ts4.isClassDeclaration(node) || node.name?.text !== `Light${moduleClassName}`) {
|
|
781
|
+
ts4.forEachChild(node, visit);
|
|
969
782
|
return;
|
|
970
783
|
}
|
|
971
784
|
const viaCall = heritageCall(node);
|
|
972
785
|
const projectionArg = viaCall?.arguments.find((arg) => {
|
|
973
|
-
const expression =
|
|
974
|
-
return
|
|
786
|
+
const expression = ts4.isAsExpression(arg) ? arg.expression : arg;
|
|
787
|
+
return ts4.isArrayLiteralExpression(expression);
|
|
975
788
|
});
|
|
976
|
-
const arrayLiteral = projectionArg ?
|
|
977
|
-
if (!projectionArg || !arrayLiteral || !
|
|
789
|
+
const arrayLiteral = projectionArg ? ts4.isAsExpression(projectionArg) ? projectionArg.expression : projectionArg : null;
|
|
790
|
+
if (!projectionArg || !arrayLiteral || !ts4.isArrayLiteralExpression(arrayLiteral))
|
|
978
791
|
return;
|
|
979
792
|
locator = {
|
|
980
793
|
projectionStart: projectionArg.getStart(source),
|
|
981
794
|
projectionEnd: projectionArg.getEnd(),
|
|
982
|
-
fields: arrayLiteral.elements.map((element) =>
|
|
795
|
+
fields: arrayLiteral.elements.map((element) => ts4.isStringLiteralLike(element) ? element.text : null).filter((field) => field !== null)
|
|
983
796
|
};
|
|
984
797
|
};
|
|
985
|
-
|
|
798
|
+
ts4.forEachChild(source, visit);
|
|
986
799
|
return locator;
|
|
987
800
|
};
|
|
988
|
-
var findNamedImport = (source, moduleSpecifier, { valueOnly = false } = {}) => {
|
|
989
|
-
for (const statement of source.statements) {
|
|
990
|
-
if (!ts2.isImportDeclaration(statement) || !ts2.isStringLiteral(statement.moduleSpecifier))
|
|
991
|
-
continue;
|
|
992
|
-
if (statement.moduleSpecifier.text !== moduleSpecifier)
|
|
993
|
-
continue;
|
|
994
|
-
if (valueOnly && statement.importClause?.isTypeOnly)
|
|
995
|
-
continue;
|
|
996
|
-
const namedBindings = statement.importClause?.namedBindings;
|
|
997
|
-
if (!namedBindings || !ts2.isNamedImports(namedBindings))
|
|
998
|
-
continue;
|
|
999
|
-
return {
|
|
1000
|
-
names: namedBindings.elements.map((element) => element.name.text),
|
|
1001
|
-
elements: namedBindings.elements.map((element) => ({ name: element.name.text, text: element.getText(source) })),
|
|
1002
|
-
namedBindingsStart: namedBindings.getStart(source),
|
|
1003
|
-
namedBindingsEnd: namedBindings.getEnd()
|
|
1004
|
-
};
|
|
1005
|
-
}
|
|
1006
|
-
return null;
|
|
1007
|
-
};
|
|
1008
801
|
var fieldExpressionBuilder = (property) => {
|
|
1009
|
-
if (!
|
|
802
|
+
if (!ts4.isPropertyAssignment(property))
|
|
1010
803
|
return null;
|
|
1011
|
-
const initializer =
|
|
1012
|
-
if (!
|
|
804
|
+
const initializer = ts4.isAsExpression(property.initializer) ? property.initializer.expression : property.initializer;
|
|
805
|
+
if (!ts4.isCallExpression(initializer))
|
|
1013
806
|
return null;
|
|
1014
807
|
return expressionName(initializer.expression);
|
|
1015
808
|
};
|
|
1016
|
-
var priorityOf = (fieldName) => {
|
|
1017
|
-
const priority = fieldOrderingPriority.indexOf(fieldName);
|
|
1018
|
-
return priority < 0 ? null : priority;
|
|
1019
|
-
};
|
|
1020
|
-
var insertionIndexForFieldOrder = (fieldNames, newFieldName) => {
|
|
1021
|
-
const newPriority = priorityOf(newFieldName);
|
|
1022
|
-
if (newPriority !== null) {
|
|
1023
|
-
const greaterPriorityIndex = fieldNames.findIndex((name) => {
|
|
1024
|
-
const existingPriority = priorityOf(name);
|
|
1025
|
-
return existingPriority !== null && existingPriority > newPriority;
|
|
1026
|
-
});
|
|
1027
|
-
if (greaterPriorityIndex >= 0)
|
|
1028
|
-
return greaterPriorityIndex;
|
|
1029
|
-
const lastPriorityIndex = fieldNames.reduce((lastIndex, name, index) => {
|
|
1030
|
-
const existingPriority = priorityOf(name);
|
|
1031
|
-
return existingPriority !== null ? index : lastIndex;
|
|
1032
|
-
}, -1);
|
|
1033
|
-
return lastPriorityIndex + 1;
|
|
1034
|
-
}
|
|
1035
|
-
const lastNonPriorityIndex = fieldNames.reduce((lastIndex, name, index) => priorityOf(name) === null ? index : lastIndex, -1);
|
|
1036
|
-
return lastNonPriorityIndex >= 0 ? lastNonPriorityIndex + 1 : fieldNames.length;
|
|
1037
|
-
};
|
|
1038
|
-
var insertOrderedFieldLine = (content, locator, fieldName, line, options) => {
|
|
1039
|
-
if (locator.fields.some((field) => field.name === fieldName))
|
|
1040
|
-
return content;
|
|
1041
|
-
const insertIndex = insertionIndexForFieldOrder(locator.fields.map((field) => field.name), fieldName);
|
|
1042
|
-
const formattedLine = line.trim();
|
|
1043
|
-
if (locator.fields.length === 0) {
|
|
1044
|
-
return spliceText(content, locator.objectStart, locator.objectEnd, `{
|
|
1045
|
-
${options.fieldIndent}${formattedLine}
|
|
1046
|
-
${options.closingIndent}}`);
|
|
1047
|
-
}
|
|
1048
|
-
const beforeField = locator.fields[insertIndex];
|
|
1049
|
-
if (beforeField) {
|
|
1050
|
-
const leadingComments = ts2.getLeadingCommentRanges(content, beforeField.fullStart) ?? [];
|
|
1051
|
-
const insertAt = lineStartAt(content, leadingComments[0]?.pos ?? beforeField.start);
|
|
1052
|
-
const indent = lineIndentAt(content, beforeField.start) || options.fieldIndent;
|
|
1053
|
-
return spliceText(content, insertAt, insertAt, `${indent}${formattedLine}
|
|
1054
|
-
`);
|
|
1055
|
-
}
|
|
1056
|
-
const afterField = locator.fields[locator.fields.length - 1];
|
|
1057
|
-
const insertAt = lineEndAt(content, afterField.end);
|
|
1058
|
-
const indent = lineIndentAt(content, afterField.start) || options.fieldIndent;
|
|
1059
|
-
return spliceText(content, insertAt, insertAt, `${indent}${formattedLine}
|
|
1060
|
-
`);
|
|
1061
|
-
};
|
|
1062
809
|
var viaBuilderParameterName = (content, className) => {
|
|
1063
810
|
const source = sourceFileFor("constant.ts", content);
|
|
1064
811
|
let builderName = null;
|
|
1065
812
|
const visit = (node) => {
|
|
1066
813
|
if (builderName !== null)
|
|
1067
814
|
return;
|
|
1068
|
-
if (!
|
|
1069
|
-
|
|
815
|
+
if (!ts4.isClassDeclaration(node) || node.name?.text !== className) {
|
|
816
|
+
ts4.forEachChild(node, visit);
|
|
1070
817
|
return;
|
|
1071
818
|
}
|
|
1072
819
|
const viaCall = heritageCall(node);
|
|
1073
|
-
const callback = viaCall?.arguments.find((arg) =>
|
|
1074
|
-
if (callback && (
|
|
820
|
+
const callback = viaCall?.arguments.find((arg) => ts4.isArrowFunction(arg) || ts4.isFunctionExpression(arg));
|
|
821
|
+
if (callback && (ts4.isArrowFunction(callback) || ts4.isFunctionExpression(callback))) {
|
|
1075
822
|
builderName = nodeName(callback.parameters[0]?.name);
|
|
1076
823
|
}
|
|
1077
824
|
};
|
|
1078
|
-
|
|
825
|
+
ts4.forEachChild(source, visit);
|
|
1079
826
|
return builderName;
|
|
1080
827
|
};
|
|
1081
828
|
var inspectConstantStructure = (content, className, moduleClassName) => {
|
|
@@ -1086,12 +833,12 @@ var inspectConstantStructure = (content, className, moduleClassName) => {
|
|
|
1086
833
|
const fields = [];
|
|
1087
834
|
if (inputObject) {
|
|
1088
835
|
const visit = (node) => {
|
|
1089
|
-
if (!
|
|
1090
|
-
|
|
836
|
+
if (!ts4.isClassDeclaration(node) || node.name?.text !== className) {
|
|
837
|
+
ts4.forEachChild(node, visit);
|
|
1091
838
|
return;
|
|
1092
839
|
}
|
|
1093
840
|
const viaCall = heritageCall(node);
|
|
1094
|
-
const callback = viaCall?.arguments.find((arg) =>
|
|
841
|
+
const callback = viaCall?.arguments.find((arg) => ts4.isArrowFunction(arg) || ts4.isFunctionExpression(arg));
|
|
1095
842
|
const objectLiteral = callback ? firstObjectReturnedByArrow(callback) : null;
|
|
1096
843
|
if (!objectLiteral)
|
|
1097
844
|
return;
|
|
@@ -1102,7 +849,7 @@ var inspectConstantStructure = (content, className, moduleClassName) => {
|
|
|
1102
849
|
return { name, expressionBuilder: fieldExpressionBuilder(property) };
|
|
1103
850
|
}).filter((field) => field !== null));
|
|
1104
851
|
};
|
|
1105
|
-
|
|
852
|
+
ts4.forEachChild(source, visit);
|
|
1106
853
|
}
|
|
1107
854
|
return {
|
|
1108
855
|
parseValid: !hasParseDiagnostics(source),
|
|
@@ -1113,17 +860,6 @@ var inspectConstantStructure = (content, className, moduleClassName) => {
|
|
|
1113
860
|
baseImports: baseImport?.names ?? []
|
|
1114
861
|
};
|
|
1115
862
|
};
|
|
1116
|
-
var inspectDictionaryStructure = (content, moduleClassName) => {
|
|
1117
|
-
const source = sourceFileFor("dictionary.ts", content);
|
|
1118
|
-
const modelObject = findDictionaryModelObject(source, moduleClassName);
|
|
1119
|
-
return {
|
|
1120
|
-
parseValid: !hasParseDiagnostics(source),
|
|
1121
|
-
modelObjectFound: modelObject !== null,
|
|
1122
|
-
chainOrderValid: modelObject ? dictionaryChainOrderValid(modelObject.chainMethods) : false,
|
|
1123
|
-
chainMethods: modelObject?.chainMethods ?? [],
|
|
1124
|
-
fields: modelObject?.fields.map((field) => field.name) ?? []
|
|
1125
|
-
};
|
|
1126
|
-
};
|
|
1127
863
|
var insertIntoObject = (content, className, line) => {
|
|
1128
864
|
const fieldName = /^([A-Za-z_$][\w$]*)\s*:/.exec(line.trim())?.[1];
|
|
1129
865
|
if (!fieldName)
|
|
@@ -1148,56 +884,149 @@ ${nextFields.map((field) => ` ${JSON.stringify(field)},`).join(`
|
|
|
1148
884
|
] as const`;
|
|
1149
885
|
return spliceText(content, locator.projectionStart, locator.projectionEnd, nextArray);
|
|
1150
886
|
};
|
|
1151
|
-
var
|
|
1152
|
-
content
|
|
1153
|
-
moduleName,
|
|
1154
|
-
moduleClassName,
|
|
1155
|
-
fieldName,
|
|
1156
|
-
component
|
|
1157
|
-
}) => {
|
|
1158
|
-
if (content.includes(`l("${moduleName}.${fieldName}")`) || content.includes(`.${fieldName}`))
|
|
887
|
+
var insertEnumClass = (content, enumClassName, enumName, values) => {
|
|
888
|
+
if (content.includes(`export class ${enumClassName} extends enumOf`))
|
|
1159
889
|
return content;
|
|
1160
|
-
const
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
return null;
|
|
1166
|
-
const fieldSetter = `st.do.set${moduleComponentName(fieldName)}On${moduleClassName}`;
|
|
1167
|
-
const fieldBlock = ` <${component}
|
|
1168
|
-
label={l("${moduleName}.${fieldName}")}
|
|
1169
|
-
desc={l("${moduleName}.${fieldName}.desc")}
|
|
1170
|
-
value={${formName}.${fieldName}}
|
|
1171
|
-
onChange={${fieldSetter}}
|
|
1172
|
-
/>
|
|
890
|
+
const enumClass = `export class ${enumClassName} extends enumOf("${enumName}", [
|
|
891
|
+
${values.map((value) => ` ${JSON.stringify(value)},`).join(`
|
|
892
|
+
`)}
|
|
893
|
+
] as const) {}
|
|
894
|
+
|
|
1173
895
|
`;
|
|
1174
|
-
|
|
896
|
+
const firstClassIndex = content.indexOf("export class ");
|
|
897
|
+
if (firstClassIndex < 0)
|
|
898
|
+
return `${content}
|
|
899
|
+
${enumClass}`;
|
|
900
|
+
return `${content.slice(0, firstClassIndex)}${enumClass}${content.slice(firstClassIndex)}`;
|
|
1175
901
|
};
|
|
1176
|
-
var
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
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];
|
|
1183
968
|
}
|
|
1184
|
-
|
|
1185
|
-
|
|
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;
|
|
1186
1019
|
};
|
|
1187
|
-
var
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
if (firstClassIndex < 0)
|
|
1198
|
-
return `${content}
|
|
1199
|
-
${enumClass}`;
|
|
1200
|
-
return `${content.slice(0, firstClassIndex)}${enumClass}${content.slice(firstClassIndex)}`;
|
|
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
|
+
};
|
|
1201
1030
|
};
|
|
1202
1031
|
var dictionaryModelFieldLine = (fieldName) => {
|
|
1203
1032
|
const label = bilingualLabelForField(fieldName);
|
|
@@ -1214,12 +1043,6 @@ var insertDictionaryModelField = (content, moduleClassName, fieldName) => {
|
|
|
1214
1043
|
closingIndent: " "
|
|
1215
1044
|
});
|
|
1216
1045
|
};
|
|
1217
|
-
var hasConstantInputField = (content, className, fieldName) => {
|
|
1218
|
-
const source = sourceFileFor("constant.ts", content);
|
|
1219
|
-
if (hasParseDiagnostics(source))
|
|
1220
|
-
return false;
|
|
1221
|
-
return findConstantInputObject(source, className)?.fields.some((field) => field.name === fieldName) ?? false;
|
|
1222
|
-
};
|
|
1223
1046
|
var hasDictionaryModelField = (content, moduleClassName, fieldName) => {
|
|
1224
1047
|
const source = sourceFileFor("dictionary.ts", content);
|
|
1225
1048
|
if (hasParseDiagnostics(source))
|
|
@@ -1237,28 +1060,16 @@ var insertDictionaryEndpointEntry = (content, moduleClassName, entryName, entryT
|
|
|
1237
1060
|
return null;
|
|
1238
1061
|
return insertOrderedFieldLine(content, locator, entryName, entryText, { fieldIndent: " ", closingIndent: " " });
|
|
1239
1062
|
};
|
|
1240
|
-
var ensureConstantTypeImport = (content, constantPath, typeName) => {
|
|
1241
|
-
if (new RegExp(`import type \\{[^}]*\\b${typeName}\\b[^}]*\\} from "${constantPath}";`).test(content))
|
|
1242
|
-
return content;
|
|
1243
|
-
const importPattern = new RegExp(`import type \\{ ([^}]+) \\} from "${constantPath}";`);
|
|
1244
|
-
const existingImport = content.match(importPattern);
|
|
1245
|
-
if (existingImport !== null) {
|
|
1246
|
-
const names = existingImport[1]?.split(",").map((name) => name.trim()) ?? [];
|
|
1247
|
-
return content.replace(existingImport[0], `import type { ${[...names, typeName].sort().join(", ")} } from "${constantPath}";`);
|
|
1248
|
-
}
|
|
1249
|
-
return `import type { ${typeName} } from "${constantPath}";
|
|
1250
|
-
${content}`;
|
|
1251
|
-
};
|
|
1252
1063
|
var dictionaryChainOf = (node) => {
|
|
1253
|
-
if (
|
|
1064
|
+
if (ts5.isCallExpression(node) && outermostFluentCall(node) === node && protectedDictionaryChainOrder.some((method) => chainMethodsForCall(node).includes(method)))
|
|
1254
1065
|
return node;
|
|
1255
|
-
return
|
|
1066
|
+
return ts5.forEachChild(node, dictionaryChainOf);
|
|
1256
1067
|
};
|
|
1257
1068
|
var chainMethodNames = (call) => {
|
|
1258
|
-
if (!
|
|
1069
|
+
if (!ts5.isCallExpression(call) || !ts5.isPropertyAccessExpression(call.expression))
|
|
1259
1070
|
return [];
|
|
1260
1071
|
const name = call.expression.name;
|
|
1261
|
-
return [...chainMethodNames(call.expression.expression), ...
|
|
1072
|
+
return [...chainMethodNames(call.expression.expression), ...ts5.isIdentifier(name) ? [name] : []];
|
|
1262
1073
|
};
|
|
1263
1074
|
var insertDictionaryEnum = (content, enumClassName, enumName, values) => {
|
|
1264
1075
|
if (content.includes(`.enum<${enumClassName}>("${enumName}"`))
|
|
@@ -1285,152 +1096,171 @@ ${enumBlock.trimEnd()}`);
|
|
|
1285
1096
|
return spliceText(content, dot, dot, `
|
|
1286
1097
|
${enumBlock}`);
|
|
1287
1098
|
};
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
var
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
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"
|
|
1300
1111
|
};
|
|
1301
|
-
|
|
1302
|
-
return found;
|
|
1303
|
-
};
|
|
1304
|
-
var firstHeritageCall = (node) => {
|
|
1305
|
-
const expression = (node.heritageClauses?.flatMap((clause) => [...clause.types]) ?? [])[0]?.expression;
|
|
1306
|
-
return expression && ts2.isCallExpression(expression) ? expression : null;
|
|
1307
|
-
};
|
|
1308
|
-
var factoryArrowOf = (call) => {
|
|
1309
|
-
const arg = call.arguments.find((argument) => ts2.isArrowFunction(argument) || ts2.isFunctionExpression(argument));
|
|
1310
|
-
return arg && (ts2.isArrowFunction(arg) || ts2.isFunctionExpression(arg)) ? arg : null;
|
|
1112
|
+
return normalizedTypes[typeName.toLowerCase()] ?? typeName;
|
|
1311
1113
|
};
|
|
1312
|
-
var
|
|
1313
|
-
|
|
1314
|
-
|
|
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);
|
|
1121
|
+
}
|
|
1122
|
+
if (typeof rawDefault !== "string")
|
|
1123
|
+
return null;
|
|
1124
|
+
const trimmed = rawDefault.trim();
|
|
1125
|
+
if (!trimmed || !Number.isFinite(Number(trimmed)))
|
|
1126
|
+
return null;
|
|
1127
|
+
if (typeName === "Int" && !/^-?\d+$/.test(trimmed))
|
|
1128
|
+
return null;
|
|
1129
|
+
return trimmed;
|
|
1315
1130
|
};
|
|
1316
|
-
var
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1131
|
+
var booleanDefault = (rawDefault) => {
|
|
1132
|
+
if (typeof rawDefault === "boolean")
|
|
1133
|
+
return String(rawDefault);
|
|
1134
|
+
if (typeof rawDefault !== "string")
|
|
1135
|
+
return null;
|
|
1136
|
+
const lowered = rawDefault.trim().toLowerCase();
|
|
1137
|
+
return lowered === "true" || lowered === "false" ? lowered : null;
|
|
1323
1138
|
};
|
|
1324
|
-
var
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
if (
|
|
1139
|
+
var dateDefault = (rawDefault) => {
|
|
1140
|
+
if (typeof rawDefault === "number" && Number.isFinite(rawDefault))
|
|
1141
|
+
return `() => dayjs(${rawDefault})`;
|
|
1142
|
+
if (typeof rawDefault !== "string")
|
|
1328
1143
|
return null;
|
|
1329
|
-
const
|
|
1330
|
-
if (
|
|
1144
|
+
const trimmed = rawDefault.trim();
|
|
1145
|
+
if (!trimmed)
|
|
1331
1146
|
return null;
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1147
|
+
if (trimmed === "now")
|
|
1148
|
+
return "() => dayjs()";
|
|
1149
|
+
if (!Number.isNaN(Date.parse(trimmed)))
|
|
1150
|
+
return `() => dayjs(${JSON.stringify(trimmed)})`;
|
|
1151
|
+
return null;
|
|
1337
1152
|
};
|
|
1338
|
-
var
|
|
1339
|
-
|
|
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 };
|
|
1340
1162
|
return {
|
|
1341
|
-
|
|
1342
|
-
|
|
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
|
+
}
|
|
1343
1173
|
};
|
|
1344
1174
|
}
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
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
|
+
};
|
|
1361
1191
|
}
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
return
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
};
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
fieldIndent: " ",
|
|
1402
|
-
closingIndent: ""
|
|
1403
|
-
});
|
|
1404
|
-
if (withEntry === content)
|
|
1405
|
-
return null;
|
|
1406
|
-
return paramEdit === "unchanged" ? withEntry : spliceText(withEntry, paramEdit.start, paramEdit.end, paramEdit.text);
|
|
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
|
+
};
|
|
1225
|
+
}
|
|
1226
|
+
return {
|
|
1227
|
+
expression: JSON.stringify(String(defaultValue)),
|
|
1228
|
+
normalized: typeof defaultValue !== "string",
|
|
1229
|
+
normalizedType
|
|
1230
|
+
};
|
|
1407
1231
|
};
|
|
1408
|
-
var
|
|
1409
|
-
const
|
|
1410
|
-
const
|
|
1411
|
-
const
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
return [];
|
|
1416
|
-
if (expressionName(statement.expression.expression) !== "describe")
|
|
1417
|
-
return [];
|
|
1418
|
-
const callback = factoryArrowOf(statement.expression);
|
|
1419
|
-
return callback && ts2.isBlock(callback.body) ? [callback.body] : [];
|
|
1420
|
-
})[0];
|
|
1421
|
-
if (!body) {
|
|
1422
|
-
const block = [`describe(${JSON.stringify(describeTitle)}, () => {`, ...render(itName, " "), "});", ""];
|
|
1423
|
-
return `${ensureNamedImport(imported, "bun:test", "describe").trimEnd()}
|
|
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) ?? [];
|
|
1424
1239
|
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
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
|
+
};
|
|
1434
1264
|
};
|
|
1435
1265
|
|
|
1436
1266
|
// pkgs/@akanjs/devkit/workflow/moduleIndex.ts
|
|
@@ -1467,7 +1297,7 @@ var parseDiagnosticsFor = (source, filePath) => {
|
|
|
1467
1297
|
return parseDiagnostics.map((diagnostic) => ({
|
|
1468
1298
|
severity: "error",
|
|
1469
1299
|
code: "module-index-typescript-parse-error",
|
|
1470
|
-
message: `TypeScript parse diagnostic TS${diagnostic.code} in ${filePath}: ${
|
|
1300
|
+
message: `TypeScript parse diagnostic TS${diagnostic.code} in ${filePath}: ${ts6.flattenDiagnosticMessageText(diagnostic.messageText, `
|
|
1471
1301
|
`)}`,
|
|
1472
1302
|
context: { target: filePath, paths: [filePath] }
|
|
1473
1303
|
}));
|
|
@@ -1486,32 +1316,32 @@ var spanFor = (source, file, node) => {
|
|
|
1486
1316
|
};
|
|
1487
1317
|
};
|
|
1488
1318
|
var expressionSummary = (expression) => {
|
|
1489
|
-
if (
|
|
1319
|
+
if (ts6.isAsExpression(expression))
|
|
1490
1320
|
return expressionSummary(expression.expression);
|
|
1491
|
-
if (
|
|
1321
|
+
if (ts6.isIdentifier(expression) || ts6.isPropertyAccessExpression(expression))
|
|
1492
1322
|
return expressionName(expression) ?? "expression";
|
|
1493
|
-
if (
|
|
1323
|
+
if (ts6.isArrayLiteralExpression(expression))
|
|
1494
1324
|
return "array-literal";
|
|
1495
|
-
if (
|
|
1325
|
+
if (ts6.isObjectLiteralExpression(expression))
|
|
1496
1326
|
return "object-literal";
|
|
1497
|
-
if (
|
|
1327
|
+
if (ts6.isStringLiteralLike(expression))
|
|
1498
1328
|
return "string-literal";
|
|
1499
|
-
if (
|
|
1329
|
+
if (ts6.isNumericLiteral(expression))
|
|
1500
1330
|
return "numeric-literal";
|
|
1501
|
-
if (expression.kind ===
|
|
1331
|
+
if (expression.kind === ts6.SyntaxKind.TrueKeyword || expression.kind === ts6.SyntaxKind.FalseKeyword) {
|
|
1502
1332
|
return "boolean-literal";
|
|
1503
1333
|
}
|
|
1504
|
-
if (
|
|
1334
|
+
if (ts6.isCallExpression(expression)) {
|
|
1505
1335
|
const callee = expressionName(expression.expression);
|
|
1506
1336
|
return callee ? `${callee}(...)` : "call-expression";
|
|
1507
1337
|
}
|
|
1508
|
-
return
|
|
1338
|
+
return ts6.SyntaxKind[expression.kind] ?? "expression";
|
|
1509
1339
|
};
|
|
1510
1340
|
var typeSummaryForInitializer = (initializer) => {
|
|
1511
1341
|
if (!initializer)
|
|
1512
1342
|
return;
|
|
1513
|
-
const expression =
|
|
1514
|
-
if (!
|
|
1343
|
+
const expression = ts6.isAsExpression(initializer) ? initializer.expression : initializer;
|
|
1344
|
+
if (!ts6.isCallExpression(expression))
|
|
1515
1345
|
return expressionSummary(expression);
|
|
1516
1346
|
const callee = expressionName(expression.expression);
|
|
1517
1347
|
const firstArg = expression.arguments[0];
|
|
@@ -1522,7 +1352,7 @@ var fieldsFromObject = (source, file, objectLiteral, kind) => objectLiteral.prop
|
|
|
1522
1352
|
const name = propertyName(property);
|
|
1523
1353
|
if (!name)
|
|
1524
1354
|
return null;
|
|
1525
|
-
const initializer =
|
|
1355
|
+
const initializer = ts6.isPropertyAssignment(property) ? property.initializer : undefined;
|
|
1526
1356
|
return {
|
|
1527
1357
|
name,
|
|
1528
1358
|
kind,
|
|
@@ -1543,8 +1373,8 @@ var parseConstantIndex = (filePath, content, moduleClassName) => {
|
|
|
1543
1373
|
let fields = [];
|
|
1544
1374
|
let lightProjection;
|
|
1545
1375
|
const visit = (node) => {
|
|
1546
|
-
if (!
|
|
1547
|
-
|
|
1376
|
+
if (!ts6.isClassDeclaration(node) || !node.name) {
|
|
1377
|
+
ts6.forEachChild(node, visit);
|
|
1548
1378
|
return;
|
|
1549
1379
|
}
|
|
1550
1380
|
const className = node.name.text;
|
|
@@ -1554,8 +1384,8 @@ var parseConstantIndex = (filePath, content, moduleClassName) => {
|
|
|
1554
1384
|
if (!viaCall)
|
|
1555
1385
|
return;
|
|
1556
1386
|
inputViaFound = true;
|
|
1557
|
-
const callback = viaCall.arguments.find((arg) =>
|
|
1558
|
-
if (callback && (
|
|
1387
|
+
const callback = viaCall.arguments.find((arg) => ts6.isArrowFunction(arg) || ts6.isFunctionExpression(arg));
|
|
1388
|
+
if (callback && (ts6.isArrowFunction(callback) || ts6.isFunctionExpression(callback))) {
|
|
1559
1389
|
inputBuilderFound = true;
|
|
1560
1390
|
builderName = nodeName(callback.parameters[0]?.name) ?? null;
|
|
1561
1391
|
const objectLiteral = firstObjectReturnedByArrow(callback);
|
|
@@ -1569,15 +1399,15 @@ var parseConstantIndex = (filePath, content, moduleClassName) => {
|
|
|
1569
1399
|
return;
|
|
1570
1400
|
if (className === `Light${moduleClassName}`) {
|
|
1571
1401
|
const projectionArg = viaCall.arguments.find((arg) => {
|
|
1572
|
-
const expression =
|
|
1573
|
-
return
|
|
1402
|
+
const expression = ts6.isAsExpression(arg) ? arg.expression : arg;
|
|
1403
|
+
return ts6.isArrayLiteralExpression(expression);
|
|
1574
1404
|
});
|
|
1575
|
-
const arrayLiteral = projectionArg ?
|
|
1576
|
-
if (arrayLiteral &&
|
|
1405
|
+
const arrayLiteral = projectionArg ? ts6.isAsExpression(projectionArg) ? projectionArg.expression : projectionArg : null;
|
|
1406
|
+
if (arrayLiteral && ts6.isArrayLiteralExpression(arrayLiteral)) {
|
|
1577
1407
|
lightProjection = {
|
|
1578
1408
|
className,
|
|
1579
1409
|
sourceSpan: spanFor(source, filePath, arrayLiteral),
|
|
1580
|
-
fields: arrayLiteral.elements.map((element, order) =>
|
|
1410
|
+
fields: arrayLiteral.elements.map((element, order) => ts6.isStringLiteralLike(element) ? {
|
|
1581
1411
|
name: element.text,
|
|
1582
1412
|
kind: "lightProjection",
|
|
1583
1413
|
order,
|
|
@@ -1588,7 +1418,7 @@ var parseConstantIndex = (filePath, content, moduleClassName) => {
|
|
|
1588
1418
|
}
|
|
1589
1419
|
}
|
|
1590
1420
|
};
|
|
1591
|
-
|
|
1421
|
+
ts6.forEachChild(source, visit);
|
|
1592
1422
|
if (!inputClass) {
|
|
1593
1423
|
diagnostics.push({
|
|
1594
1424
|
severity: "error",
|
|
@@ -1636,22 +1466,22 @@ var parseDictionaryIndex = (filePath, content, moduleClassName) => {
|
|
|
1636
1466
|
let index;
|
|
1637
1467
|
let modelFound = false;
|
|
1638
1468
|
const visit = (node) => {
|
|
1639
|
-
if (modelFound || !
|
|
1640
|
-
|
|
1469
|
+
if (modelFound || !ts6.isCallExpression(node)) {
|
|
1470
|
+
ts6.forEachChild(node, visit);
|
|
1641
1471
|
return;
|
|
1642
1472
|
}
|
|
1643
1473
|
if (callExpressionName(node) !== "model") {
|
|
1644
|
-
|
|
1474
|
+
ts6.forEachChild(node, visit);
|
|
1645
1475
|
return;
|
|
1646
1476
|
}
|
|
1647
1477
|
const typeArgument = node.typeArguments?.[0];
|
|
1648
1478
|
if (!typeArgument || typeArgument.getText(source) !== moduleClassName) {
|
|
1649
|
-
|
|
1479
|
+
ts6.forEachChild(node, visit);
|
|
1650
1480
|
return;
|
|
1651
1481
|
}
|
|
1652
1482
|
modelFound = true;
|
|
1653
|
-
const callback = node.arguments.find((arg) =>
|
|
1654
|
-
if (!callback || !
|
|
1483
|
+
const callback = node.arguments.find((arg) => ts6.isArrowFunction(arg) || ts6.isFunctionExpression(arg));
|
|
1484
|
+
if (!callback || !ts6.isArrowFunction(callback) && !ts6.isFunctionExpression(callback)) {
|
|
1655
1485
|
diagnostics.push({
|
|
1656
1486
|
severity: "error",
|
|
1657
1487
|
code: "module-index-dictionary-builder-missing",
|
|
@@ -1677,7 +1507,7 @@ var parseDictionaryIndex = (filePath, content, moduleClassName) => {
|
|
|
1677
1507
|
sourceSpan: spanFor(source, filePath, node)
|
|
1678
1508
|
};
|
|
1679
1509
|
};
|
|
1680
|
-
|
|
1510
|
+
ts6.forEachChild(source, visit);
|
|
1681
1511
|
return { index, diagnostics, modelFound };
|
|
1682
1512
|
};
|
|
1683
1513
|
var expectedFilesFor = (module) => {
|
|
@@ -1850,9 +1680,9 @@ var postApplyDiagnostic = (code, message, target, severity = "error") => ({
|
|
|
1850
1680
|
});
|
|
1851
1681
|
var sourceKindForPath = (filePath) => {
|
|
1852
1682
|
if (filePath.endsWith(".tsx"))
|
|
1853
|
-
return
|
|
1683
|
+
return ts7.ScriptKind.TSX;
|
|
1854
1684
|
if (filePath.endsWith(".ts"))
|
|
1855
|
-
return
|
|
1685
|
+
return ts7.ScriptKind.TS;
|
|
1856
1686
|
return null;
|
|
1857
1687
|
};
|
|
1858
1688
|
var checkPathCasing = async (workspace, filePath) => {
|
|
@@ -1880,7 +1710,7 @@ var checkTypeScriptSyntax = async (workspace, filePath) => {
|
|
|
1880
1710
|
if (!scriptKind)
|
|
1881
1711
|
return null;
|
|
1882
1712
|
const content = await workspace.readFile(filePath);
|
|
1883
|
-
const source =
|
|
1713
|
+
const source = ts7.createSourceFile(filePath, content, ts7.ScriptTarget.Latest, true, scriptKind);
|
|
1884
1714
|
const diagnostic = (source.parseDiagnostics ?? [])[0];
|
|
1885
1715
|
if (!diagnostic)
|
|
1886
1716
|
return null;
|
|
@@ -1888,7 +1718,7 @@ var checkTypeScriptSyntax = async (workspace, filePath) => {
|
|
|
1888
1718
|
const location = position ? `:${position.line + 1}:${position.character + 1}` : "";
|
|
1889
1719
|
return {
|
|
1890
1720
|
code: "workflow-post-apply-syntax-error",
|
|
1891
|
-
message: `Generated source has a TypeScript syntax error at ${filePath}${location}: ${
|
|
1721
|
+
message: `Generated source has a TypeScript syntax error at ${filePath}${location}: ${ts7.flattenDiagnosticMessageText(diagnostic.messageText, " ")}`
|
|
1892
1722
|
};
|
|
1893
1723
|
};
|
|
1894
1724
|
var checkChangedFile = async (workspace, file) => {
|
|
@@ -2045,9 +1875,9 @@ var resolveWorkflowSys = async (workspace, target) => {
|
|
|
2045
1875
|
return null;
|
|
2046
1876
|
const [apps, libs] = await workspace.getSyss();
|
|
2047
1877
|
if (apps.includes(target))
|
|
2048
|
-
return
|
|
1878
|
+
return AppExecutor2.from(workspace, target);
|
|
2049
1879
|
if (libs.includes(target))
|
|
2050
|
-
return
|
|
1880
|
+
return LibExecutor2.from(workspace, target);
|
|
2051
1881
|
return null;
|
|
2052
1882
|
};
|
|
2053
1883
|
var targetMissing = (input = "app") => ({
|
|
@@ -2309,7 +2139,7 @@ class WorkflowExecutor {
|
|
|
2309
2139
|
}
|
|
2310
2140
|
}
|
|
2311
2141
|
// pkgs/@akanjs/devkit/workflow/fieldType.ts
|
|
2312
|
-
import
|
|
2142
|
+
import ts8 from "typescript";
|
|
2313
2143
|
var builtInFieldTypes = new Set(["String", "Boolean", "Date", "Map"]);
|
|
2314
2144
|
var baseFieldTypes = new Set(["Int", "Float", "ID", "Any", "Binary", "ImageResult"]);
|
|
2315
2145
|
var fieldTypeReference = /^\[*([A-Za-z_$][\w$]*)((?:\.[A-Za-z_$][\w$]*)*)\]*$/;
|
|
@@ -2322,24 +2152,24 @@ var ensureBaseTypeImport = (content, typeName) => {
|
|
|
2322
2152
|
var valueNamesOf = (content) => {
|
|
2323
2153
|
const names = new Set;
|
|
2324
2154
|
for (const statement of sourceFileFor("source.ts", content).statements) {
|
|
2325
|
-
if (
|
|
2155
|
+
if (ts8.isImportDeclaration(statement)) {
|
|
2326
2156
|
const clause = statement.importClause;
|
|
2327
2157
|
if (!clause || clause.isTypeOnly)
|
|
2328
2158
|
continue;
|
|
2329
2159
|
if (clause.name)
|
|
2330
2160
|
names.add(clause.name.text);
|
|
2331
2161
|
const bindings = clause.namedBindings;
|
|
2332
|
-
if (bindings &&
|
|
2162
|
+
if (bindings && ts8.isNamespaceImport(bindings))
|
|
2333
2163
|
names.add(bindings.name.text);
|
|
2334
2164
|
else
|
|
2335
2165
|
for (const element of bindings?.elements ?? [])
|
|
2336
2166
|
if (!element.isTypeOnly)
|
|
2337
2167
|
names.add(element.name.text);
|
|
2338
|
-
} else if (
|
|
2168
|
+
} else if (ts8.isVariableStatement(statement)) {
|
|
2339
2169
|
for (const declaration of statement.declarationList.declarations)
|
|
2340
|
-
if (
|
|
2170
|
+
if (ts8.isIdentifier(declaration.name))
|
|
2341
2171
|
names.add(declaration.name.text);
|
|
2342
|
-
} else if ((
|
|
2172
|
+
} else if ((ts8.isClassDeclaration(statement) || ts8.isEnumDeclaration(statement) || ts8.isFunctionDeclaration(statement)) && statement.name)
|
|
2343
2173
|
names.add(statement.name.text);
|
|
2344
2174
|
}
|
|
2345
2175
|
return names;
|
|
@@ -2469,7 +2299,7 @@ class GuardCatalog {
|
|
|
2469
2299
|
// pkgs/@akanjs/devkit/workflow/keyRename.ts
|
|
2470
2300
|
import { readFile } from "fs/promises";
|
|
2471
2301
|
import path2 from "path";
|
|
2472
|
-
import
|
|
2302
|
+
import ts9 from "typescript";
|
|
2473
2303
|
var indexedPath = /^(apps|libs)\/(?!(?:.*\/)?(?:node_modules|dist|\.akan)\/).*\.tsx?$/;
|
|
2474
2304
|
var keyPattern = /^[a-z][A-Za-z0-9]*$/;
|
|
2475
2305
|
var slashed = (fileName) => fileName.replace(/\\/g, "/");
|
|
@@ -2498,7 +2328,7 @@ class KeyRename {
|
|
|
2498
2328
|
const sourceRelative = `${getSysRoot(sys)}/${family === "slice" ? paths.signal : paths.document}`;
|
|
2499
2329
|
const sourcePath = slashed(path2.join(root, sourceRelative));
|
|
2500
2330
|
const texts = new Map;
|
|
2501
|
-
const index = new AkanIndex({ ts:
|
|
2331
|
+
const index = new AkanIndex({ ts: ts9, root });
|
|
2502
2332
|
for (const relative of await workspace.getAllFiles("{apps,libs}/**/*.{ts,tsx}")) {
|
|
2503
2333
|
if (!indexedPath.test(slashed(relative)))
|
|
2504
2334
|
continue;
|
|
@@ -2719,6 +2549,138 @@ class MutationSource {
|
|
|
2719
2549
|
}
|
|
2720
2550
|
}
|
|
2721
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
|
+
|
|
2722
2684
|
// pkgs/@akanjs/devkit/workflow/mutationScaffold.ts
|
|
2723
2685
|
class MutationScaffold {
|
|
2724
2686
|
static #documentMethods = new Set(["isModified", "refresh", "remove", "save", "set", "toJSON", "toObject"]);
|
|
@@ -3919,4 +3881,76 @@ for (const candidate of toolingRolloutCandidates) {
|
|
|
3919
3881
|
if (isRestrictedCandidate(candidate))
|
|
3920
3882
|
restrictedCandidates.set(candidate.packageName, candidate);
|
|
3921
3883
|
}
|
|
3922
|
-
|
|
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 };
|