@akanjs/cli 3.2.0-rc.18 → 3.2.0-rc.19
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-w96z7fm7.js → CodeAgent-q0xkt4at.js} +2 -2
- package/{CodeTui-496f55hh.js → CodeTui-n56kpaca.js} +819 -663
- package/TunnelShare-844s9te4.js +18 -0
- package/{agent.command-81h65wcv.js → agent.command-k07raqft.js} +20 -20
- package/akanCode.js +8 -8
- package/{appExecutor-g4wq24v1.js → appExecutor-xav1zemr.js} +3 -3
- package/{application.command-rcw4h1gh.js → application.command-dv8y8r12.js} +52 -25
- package/{applicationBuildRunner-emhp6rh0.js → applicationBuildRunner-vhx7zq97.js} +9 -10
- package/buildBatch.proc.js +20 -11
- package/{cloud.command-k47h3kma.js → cloud.command-0vjy3x96.js} +22 -22
- package/cloud.script-jp48r0kw.js +35 -0
- package/{code.command-dam01a2f.js → code.command-xc5exq4b.js} +10 -10
- package/{context.command-44carkt5.js → context.command-etsat8yk.js} +22 -22
- package/context.runner-e52ak0cx.js +34 -0
- package/{guideline.command-ccxs69br.js → guideline.command-zqkntk7b.js} +6 -6
- package/guidelines/agentRule/agentRule.instruction.md +5 -4
- package/guidelines/conventions/core.md +18 -0
- package/guidelines/errorCodes/errorCodes.instruction.md +6 -0
- package/guidelines/mcpRule/mcpRule.instruction.md +4 -2
- package/guidelines/transportRule/transportRule.instruction.md +3 -1
- package/incrementalBuilder.proc.js +559 -409
- package/{index-aw7at6j6.js → index-12js5pj4.js} +1 -1
- package/{index-tpr9nqkj.js → index-12vv4g80.js} +1 -1
- package/index-4zqebbqb.js +80 -0
- package/{index-rxxjkbj2.js → index-6bryy19d.js} +499 -421
- package/{index-2hwjhe8r.js → index-6pzncry1.js} +4 -4
- package/{index-jeqq717b.js → index-6rrh0ffr.js} +44 -32
- package/{index-a42cf737.js → index-7jr9mfp2.js} +235 -105
- package/{index-pcqr0r0m.js → index-81qt1jyj.js} +1 -1
- package/{index-2mrn1mrg.js → index-9f3reh2y.js} +1 -1
- package/{index-h9356zmz.js → index-a05ewnnp.js} +1 -1
- package/{index-ptpdd9hw.js → index-bxevbjw7.js} +8 -8
- package/{index-g95rbz83.js → index-c1vym3gx.js} +2 -2
- package/{index-vh8q7mrq.js → index-c9hd79py.js} +4 -4
- package/{index-wy7qcqsd.js → index-c9mnfy9r.js} +38 -23
- package/{index-a85n83t6.js → index-cc9pevta.js} +1 -1
- package/{index-4279crca.js → index-cet2s7xk.js} +2 -2
- package/{index-k1p29hdp.js → index-dasa0kbj.js} +2 -2
- package/{index-y27cxjd6.js → index-ddc2zjj5.js} +1 -1
- package/{index-r790hx48.js → index-dz7z9n9t.js} +25 -25
- package/{index-mgvvtjp1.js → index-e4vna9dn.js} +4 -4
- package/{index-ggmwp14t.js → index-ean2tff1.js} +723 -691
- package/{index-s21zxj7p.js → index-fgp04fh7.js} +6 -6
- package/{index-cef0fxf2.js → index-g541mhzw.js} +3 -3
- package/{index-rj406y9n.js → index-gh741qft.js} +8 -8
- package/{index-sa8g94se.js → index-k51718xz.js} +2138 -2138
- package/{index-286djj0d.js → index-m6r3pvf5.js} +2 -2
- package/{index-kqf2s304.js → index-my17308p.js} +7 -7
- package/{index-pqf6d5ff.js → index-nd8bq17n.js} +6 -6
- package/{index-her656ng.js → index-nxcmgqk3.js} +3 -3
- package/{index-gd9tkq2k.js → index-pkgha3rt.js} +5 -5
- package/{index-tkrg58qv.js → index-q2t2w996.js} +1 -1
- package/{index-b061e6fn.js → index-qtqhsb33.js} +204 -160
- package/{index-nwbdpnna.js → index-rj2n5kfk.js} +67 -67
- package/{index-ktvyva62.js → index-s5gvwvkb.js} +103 -138
- package/{index-bbd1727m.js → index-sh3yzse2.js} +8 -7
- package/{index-y71v7grx.js → index-syn4vm3y.js} +1 -1
- package/{index-gkfpqdm8.js → index-t00xrkey.js} +1 -1
- package/{index-hw2eammf.js → index-v72mh89f.js} +5 -6
- package/{index-qrh7kdb1.js → index-wq8pnev4.js} +3 -3
- package/{index-1j1jmmac.js → index-wxr3941g.js} +8 -8
- package/{index-e4w015qt.js → index-y8mqkhcf.js} +1 -1
- package/{index-ctrx7asj.js → index-zk1gjk46.js} +4 -4
- package/index.js +27 -27
- package/{libExecutor-mmrzd606.js → libExecutor-mr3vxtnr.js} +2 -2
- package/{library.command-brkcat13.js → library.command-ps9q5t37.js} +7 -7
- package/{localRegistry.command-qwzy3t7w.js → localRegistry.command-rszxmvd0.js} +21 -21
- package/{module.command-t5emqxkr.js → module.command-fcybnn1a.js} +10 -10
- package/{package.command-xv04dbxf.js → package.command-zen3rhye.js} +10 -10
- package/package.json +2 -2
- package/{page.command-yhgq9tj8.js → page.command-gwrxymms.js} +7 -7
- package/{pipeline.command-x3nkf9kc.js → pipeline.command-m1brkqqw.js} +6 -6
- package/{pkgExecutor-4cbe3sgr.js → pkgExecutor-x51agavp.js} +2 -2
- package/{primitive.command-jv60b759.js → primitive.command-5vkxvvmk.js} +11 -11
- package/{projectTypecheck-fbfq9rm9.js → projectTypecheck-9dzfah37.js} +1 -1
- package/{quality.command-mdjardf1.js → quality.command-gqry7eas.js} +9 -9
- package/{repair.command-s22j5xbe.js → repair.command-qs4ejcrg.js} +10 -10
- package/{scalar.command-a6qs7012.js → scalar.command-ny0vchqq.js} +9 -9
- package/skills/akan-scaffold/SKILL.md +1 -1
- package/{subspace.command-26hkjqf9.js → subspace.command-5pxqjgmw.js} +12 -12
- package/templates/workspaceRoot/AGENTS.md.template +2 -1
- package/{tunnel.command-83sfgz5z.js → tunnel.command-ndajt0xk.js} +11 -11
- package/{verify.command-krm1rrf1.js → verify.command-m59ashc7.js} +17 -17
- package/{workflow.command-z05y7amj.js → workflow.command-jchqey88.js} +15 -15
- package/{workspace.command-qga6cn1n.js → workspace.command-g0gzxkpd.js} +36 -36
- package/TunnelShare-tyj8nb0z.js +0 -19
- package/cloud.script-b4smdpa5.js +0 -35
- package/context.runner-xtr9ngpa.js +0 -34
- package/index-k2kr1wd4.js +0 -18
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
3
|
AppExecutor2
|
|
4
|
-
} from "./index-
|
|
4
|
+
} from "./index-cet2s7xk.js";
|
|
5
5
|
import {
|
|
6
6
|
LibExecutor2
|
|
7
|
-
} from "./index-
|
|
7
|
+
} from "./index-t00xrkey.js";
|
|
8
8
|
import {
|
|
9
9
|
createAst,
|
|
10
10
|
AkanIndex
|
|
11
|
-
} from "./index-
|
|
11
|
+
} from "./index-7jr9mfp2.js";
|
|
12
12
|
import {
|
|
13
13
|
sysNamePattern,
|
|
14
14
|
identifierPattern
|
|
15
15
|
} from "./index-va90m8nd.js";
|
|
16
16
|
import {
|
|
17
17
|
camelToKebabCase
|
|
18
|
-
} from "./index-
|
|
18
|
+
} from "./index-sh3yzse2.js";
|
|
19
19
|
|
|
20
20
|
// pkgs/@akanjs/devkit/workflow/artifacts.ts
|
|
21
21
|
import { capitalize as capitalize2 } from "akanjs/common";
|
|
@@ -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
|
|
534
|
+
import ts7 from "typescript";
|
|
535
535
|
|
|
536
|
-
// pkgs/@akanjs/devkit/workflow/
|
|
537
|
-
import
|
|
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/
|
|
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
|
-
|
|
558
|
-
var
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
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
|
|
583
|
-
|
|
584
|
-
|
|
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
|
|
649
|
-
|
|
650
|
-
|
|
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
|
-
|
|
657
|
-
|
|
658
|
-
|
|
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
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
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
|
|
668
|
-
const
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
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) =>
|
|
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,244 +709,67 @@ ${line}
|
|
|
721
709
|
`);
|
|
722
710
|
};
|
|
723
711
|
var ensureBaseImport = (content, name) => ensureNamedImport(content, "akanjs/base", name);
|
|
724
|
-
var
|
|
725
|
-
|
|
726
|
-
if (!
|
|
727
|
-
|
|
728
|
-
if (
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
if (!trimmed || !Number.isFinite(Number(trimmed)))
|
|
736
|
-
return null;
|
|
737
|
-
if (typeName === "Int" && !/^-?\d+$/.test(trimmed))
|
|
738
|
-
return null;
|
|
739
|
-
return trimmed;
|
|
740
|
-
};
|
|
741
|
-
var booleanDefault = (rawDefault) => {
|
|
742
|
-
if (typeof rawDefault === "boolean")
|
|
743
|
-
return String(rawDefault);
|
|
744
|
-
if (typeof rawDefault !== "string")
|
|
745
|
-
return null;
|
|
746
|
-
const lowered = rawDefault.trim().toLowerCase();
|
|
747
|
-
return lowered === "true" || lowered === "false" ? lowered : null;
|
|
748
|
-
};
|
|
749
|
-
var dateDefault = (rawDefault) => {
|
|
750
|
-
if (typeof rawDefault === "number" && Number.isFinite(rawDefault))
|
|
751
|
-
return `() => dayjs(${rawDefault})`;
|
|
752
|
-
if (typeof rawDefault !== "string")
|
|
753
|
-
return null;
|
|
754
|
-
const trimmed = rawDefault.trim();
|
|
755
|
-
if (!trimmed)
|
|
756
|
-
return null;
|
|
757
|
-
if (trimmed === "now")
|
|
758
|
-
return "() => dayjs()";
|
|
759
|
-
if (!Number.isNaN(Date.parse(trimmed)))
|
|
760
|
-
return `() => dayjs(${JSON.stringify(trimmed)})`;
|
|
761
|
-
return null;
|
|
762
|
-
};
|
|
763
|
-
var coerceFieldDefault = (typeName, defaultValue, options = {}) => {
|
|
764
|
-
const normalizedType = typeName.toLowerCase() === "enum" ? "enum" : normalizeFieldType(typeName);
|
|
765
|
-
if (defaultValue === undefined || defaultValue === null || defaultValue === "") {
|
|
766
|
-
return { expression: null, normalized: false, normalizedType };
|
|
767
|
-
}
|
|
768
|
-
if (normalizedType === "Int" || normalizedType === "Float") {
|
|
769
|
-
const expression = numericDefault(normalizedType, defaultValue);
|
|
770
|
-
if (expression !== null)
|
|
771
|
-
return { expression, normalized: typeof defaultValue === "string", normalizedType };
|
|
772
|
-
return {
|
|
773
|
-
expression: null,
|
|
774
|
-
normalized: false,
|
|
775
|
-
normalizedType,
|
|
776
|
-
diagnostic: {
|
|
777
|
-
severity: "error",
|
|
778
|
-
code: "primitive-default-value-invalid",
|
|
779
|
-
input: "default",
|
|
780
|
-
failureScope: "source-change",
|
|
781
|
-
message: `Default value for ${normalizedType} must be a numeric literal. Received: ${JSON.stringify(defaultValue)}.`
|
|
782
|
-
}
|
|
783
|
-
};
|
|
784
|
-
}
|
|
785
|
-
if (normalizedType === "Boolean") {
|
|
786
|
-
const expression = booleanDefault(defaultValue);
|
|
787
|
-
if (expression !== null)
|
|
788
|
-
return { expression, normalized: typeof defaultValue === "string", normalizedType };
|
|
789
|
-
return {
|
|
790
|
-
expression: null,
|
|
791
|
-
normalized: false,
|
|
792
|
-
normalizedType,
|
|
793
|
-
diagnostic: {
|
|
794
|
-
severity: "error",
|
|
795
|
-
code: "primitive-default-value-invalid",
|
|
796
|
-
input: "default",
|
|
797
|
-
failureScope: "source-change",
|
|
798
|
-
message: `Default value for Boolean must be true or false. Received: ${JSON.stringify(defaultValue)}.`
|
|
799
|
-
}
|
|
800
|
-
};
|
|
801
|
-
}
|
|
802
|
-
if (normalizedType === "Date") {
|
|
803
|
-
const expression = dateDefault(defaultValue);
|
|
804
|
-
if (expression !== null)
|
|
805
|
-
return { expression, normalized: true, normalizedType };
|
|
806
|
-
return {
|
|
807
|
-
expression: null,
|
|
808
|
-
normalized: false,
|
|
809
|
-
normalizedType,
|
|
810
|
-
diagnostic: {
|
|
811
|
-
severity: "error",
|
|
812
|
-
code: "primitive-default-value-invalid",
|
|
813
|
-
input: "default",
|
|
814
|
-
failureScope: "source-change",
|
|
815
|
-
message: `Default value for Date must be "now", a timestamp, or a parseable date string. Received: ${JSON.stringify(defaultValue)}.`
|
|
816
|
-
}
|
|
817
|
-
};
|
|
818
|
-
}
|
|
819
|
-
if (normalizedType === "enum") {
|
|
820
|
-
if (typeof defaultValue === "string" && options.enumValues?.includes(defaultValue)) {
|
|
821
|
-
return { expression: JSON.stringify(defaultValue), normalized: false, normalizedType };
|
|
822
|
-
}
|
|
823
|
-
return {
|
|
824
|
-
expression: null,
|
|
825
|
-
normalized: false,
|
|
826
|
-
normalizedType,
|
|
827
|
-
diagnostic: {
|
|
828
|
-
severity: "error",
|
|
829
|
-
code: "primitive-default-value-invalid",
|
|
830
|
-
input: "default",
|
|
831
|
-
failureScope: "source-change",
|
|
832
|
-
message: `Default value for enum must be one of: ${(options.enumValues ?? []).join(", ")}. Received: ${JSON.stringify(defaultValue)}.`
|
|
833
|
-
}
|
|
834
|
-
};
|
|
835
|
-
}
|
|
836
|
-
return {
|
|
837
|
-
expression: JSON.stringify(String(defaultValue)),
|
|
838
|
-
normalized: typeof defaultValue !== "string",
|
|
839
|
-
normalizedType
|
|
840
|
-
};
|
|
841
|
-
};
|
|
842
|
-
var fieldExpression = (typeName, defaultValue, options = {}) => {
|
|
843
|
-
const typeExpression = normalizeFieldType(typeName);
|
|
844
|
-
const defaultExpression = coerceFieldDefault(options.enumValues ? "enum" : typeExpression, defaultValue, options).expression;
|
|
845
|
-
const defaultOption = defaultExpression ? `, { default: ${defaultExpression} }` : "";
|
|
846
|
-
return `${options.builderName ?? "field"}(${typeExpression}${defaultOption})`;
|
|
847
|
-
};
|
|
848
|
-
var fieldOrderingPriority = [
|
|
849
|
-
"id",
|
|
850
|
-
"name",
|
|
851
|
-
"title",
|
|
852
|
-
"status",
|
|
853
|
-
"category",
|
|
854
|
-
"description",
|
|
855
|
-
"content",
|
|
856
|
-
"startAt",
|
|
857
|
-
"dueAt",
|
|
858
|
-
"endAt",
|
|
859
|
-
"createdAt",
|
|
860
|
-
"updatedAt"
|
|
861
|
-
];
|
|
862
|
-
var hasParseDiagnostics = (source) => (source.parseDiagnostics ?? []).length > 0;
|
|
863
|
-
var spliceText = (content, start, end, replacement) => `${content.slice(0, start)}${replacement}${content.slice(end)}`;
|
|
864
|
-
var lineStartAt = (content, position) => content.lastIndexOf(`
|
|
865
|
-
`, Math.max(0, position - 1)) + 1;
|
|
866
|
-
var lineEndAt = (content, position) => {
|
|
867
|
-
const end = content.indexOf(`
|
|
868
|
-
`, position);
|
|
869
|
-
return end < 0 ? content.length : end + 1;
|
|
870
|
-
};
|
|
871
|
-
var lineIndentAt = (content, position) => /^[ \t]*/.exec(content.slice(lineStartAt(content, position)))?.[0] ?? "";
|
|
872
|
-
var locatedObject = (source, objectLiteral) => ({
|
|
873
|
-
objectStart: objectLiteral.getStart(source),
|
|
874
|
-
objectEnd: objectLiteral.getEnd(),
|
|
875
|
-
fields: objectLiteral.properties.map((property) => {
|
|
876
|
-
const name = propertyName(property);
|
|
877
|
-
if (!name)
|
|
878
|
-
return null;
|
|
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;
|
|
879
723
|
return {
|
|
880
|
-
name,
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
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()
|
|
884
728
|
};
|
|
885
|
-
}).filter((field) => field !== null)
|
|
886
|
-
});
|
|
887
|
-
var findConstantInputObject = (source, className) => {
|
|
888
|
-
let locator = null;
|
|
889
|
-
const visit = (node) => {
|
|
890
|
-
if (locator)
|
|
891
|
-
return;
|
|
892
|
-
if (!ts2.isClassDeclaration(node) || node.name?.text !== className) {
|
|
893
|
-
ts2.forEachChild(node, visit);
|
|
894
|
-
return;
|
|
895
|
-
}
|
|
896
|
-
const viaCall = heritageCall(node);
|
|
897
|
-
const callback = viaCall?.arguments.find((arg) => ts2.isArrowFunction(arg) || ts2.isFunctionExpression(arg));
|
|
898
|
-
const objectLiteral = callback ? firstObjectReturnedByArrow(callback) : null;
|
|
899
|
-
if (objectLiteral)
|
|
900
|
-
locator = locatedObject(source, objectLiteral);
|
|
901
|
-
};
|
|
902
|
-
ts2.forEachChild(source, visit);
|
|
903
|
-
return locator;
|
|
904
|
-
};
|
|
905
|
-
var chainMethodsForCall = (node) => {
|
|
906
|
-
if (ts2.isAsExpression(node) || ts2.isParenthesizedExpression(node))
|
|
907
|
-
return chainMethodsForCall(node.expression);
|
|
908
|
-
if (!ts2.isCallExpression(node))
|
|
909
|
-
return [];
|
|
910
|
-
if (ts2.isPropertyAccessExpression(node.expression)) {
|
|
911
|
-
return [...chainMethodsForCall(node.expression.expression), node.expression.name.text];
|
|
912
729
|
}
|
|
913
|
-
|
|
914
|
-
return name ? [name] : [];
|
|
730
|
+
return null;
|
|
915
731
|
};
|
|
916
|
-
var
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
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";`);
|
|
920
739
|
}
|
|
921
|
-
return
|
|
740
|
+
return `import { enumOf } from "akanjs/base";
|
|
741
|
+
${content}`;
|
|
922
742
|
};
|
|
923
|
-
var
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
if (order < lastOrder)
|
|
932
|
-
return false;
|
|
933
|
-
lastOrder = order;
|
|
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}";`);
|
|
934
751
|
}
|
|
935
|
-
return
|
|
752
|
+
return `import type { ${typeName} } from "${constantPath}";
|
|
753
|
+
${content}`;
|
|
936
754
|
};
|
|
937
|
-
|
|
938
|
-
|
|
755
|
+
|
|
756
|
+
// pkgs/@akanjs/devkit/workflow/constantSource.ts
|
|
757
|
+
var findConstantInputObject = (source, className) => {
|
|
939
758
|
let locator = null;
|
|
940
759
|
const visit = (node) => {
|
|
941
760
|
if (locator)
|
|
942
761
|
return;
|
|
943
|
-
if (!
|
|
944
|
-
|
|
945
|
-
return;
|
|
946
|
-
}
|
|
947
|
-
const typeArgument = node.typeArguments?.[0];
|
|
948
|
-
if (!typeArgument || typeArgument.getText(source) !== typeName) {
|
|
949
|
-
ts2.forEachChild(node, visit);
|
|
762
|
+
if (!ts4.isClassDeclaration(node) || node.name?.text !== className) {
|
|
763
|
+
ts4.forEachChild(node, visit);
|
|
950
764
|
return;
|
|
951
765
|
}
|
|
952
|
-
const
|
|
766
|
+
const viaCall = heritageCall(node);
|
|
767
|
+
const callback = viaCall?.arguments.find((arg) => ts4.isArrowFunction(arg) || ts4.isFunctionExpression(arg));
|
|
953
768
|
const objectLiteral = callback ? firstObjectReturnedByArrow(callback) : null;
|
|
954
|
-
if (objectLiteral)
|
|
955
|
-
locator =
|
|
956
|
-
...locatedObject(source, objectLiteral),
|
|
957
|
-
chainMethods: chainMethodsForCall(outermostFluentCall(node))
|
|
958
|
-
};
|
|
959
|
-
}
|
|
769
|
+
if (objectLiteral)
|
|
770
|
+
locator = locatedObject(source, objectLiteral);
|
|
960
771
|
};
|
|
961
|
-
|
|
772
|
+
ts4.forEachChild(source, visit);
|
|
962
773
|
return locator;
|
|
963
774
|
};
|
|
964
775
|
var findLightProjectionArray = (source, moduleClassName) => {
|
|
@@ -966,118 +777,52 @@ var findLightProjectionArray = (source, moduleClassName) => {
|
|
|
966
777
|
const visit = (node) => {
|
|
967
778
|
if (locator)
|
|
968
779
|
return;
|
|
969
|
-
if (!
|
|
970
|
-
|
|
780
|
+
if (!ts4.isClassDeclaration(node) || node.name?.text !== `Light${moduleClassName}`) {
|
|
781
|
+
ts4.forEachChild(node, visit);
|
|
971
782
|
return;
|
|
972
783
|
}
|
|
973
784
|
const viaCall = heritageCall(node);
|
|
974
785
|
const projectionArg = viaCall?.arguments.find((arg) => {
|
|
975
|
-
const expression =
|
|
976
|
-
return
|
|
786
|
+
const expression = ts4.isAsExpression(arg) ? arg.expression : arg;
|
|
787
|
+
return ts4.isArrayLiteralExpression(expression);
|
|
977
788
|
});
|
|
978
|
-
const arrayLiteral = projectionArg ?
|
|
979
|
-
if (!projectionArg || !arrayLiteral || !
|
|
789
|
+
const arrayLiteral = projectionArg ? ts4.isAsExpression(projectionArg) ? projectionArg.expression : projectionArg : null;
|
|
790
|
+
if (!projectionArg || !arrayLiteral || !ts4.isArrayLiteralExpression(arrayLiteral))
|
|
980
791
|
return;
|
|
981
792
|
locator = {
|
|
982
793
|
projectionStart: projectionArg.getStart(source),
|
|
983
794
|
projectionEnd: projectionArg.getEnd(),
|
|
984
|
-
fields: arrayLiteral.elements.map((element) =>
|
|
795
|
+
fields: arrayLiteral.elements.map((element) => ts4.isStringLiteralLike(element) ? element.text : null).filter((field) => field !== null)
|
|
985
796
|
};
|
|
986
797
|
};
|
|
987
|
-
|
|
798
|
+
ts4.forEachChild(source, visit);
|
|
988
799
|
return locator;
|
|
989
800
|
};
|
|
990
|
-
var findNamedImport = (source, moduleSpecifier, { valueOnly = false } = {}) => {
|
|
991
|
-
for (const statement of source.statements) {
|
|
992
|
-
if (!ts2.isImportDeclaration(statement) || !ts2.isStringLiteral(statement.moduleSpecifier))
|
|
993
|
-
continue;
|
|
994
|
-
if (statement.moduleSpecifier.text !== moduleSpecifier)
|
|
995
|
-
continue;
|
|
996
|
-
if (valueOnly && statement.importClause?.isTypeOnly)
|
|
997
|
-
continue;
|
|
998
|
-
const namedBindings = statement.importClause?.namedBindings;
|
|
999
|
-
if (!namedBindings || !ts2.isNamedImports(namedBindings))
|
|
1000
|
-
continue;
|
|
1001
|
-
return {
|
|
1002
|
-
names: namedBindings.elements.map((element) => element.name.text),
|
|
1003
|
-
elements: namedBindings.elements.map((element) => ({ name: element.name.text, text: element.getText(source) })),
|
|
1004
|
-
namedBindingsStart: namedBindings.getStart(source),
|
|
1005
|
-
namedBindingsEnd: namedBindings.getEnd()
|
|
1006
|
-
};
|
|
1007
|
-
}
|
|
1008
|
-
return null;
|
|
1009
|
-
};
|
|
1010
801
|
var fieldExpressionBuilder = (property) => {
|
|
1011
|
-
if (!
|
|
802
|
+
if (!ts4.isPropertyAssignment(property))
|
|
1012
803
|
return null;
|
|
1013
|
-
const initializer =
|
|
1014
|
-
if (!
|
|
804
|
+
const initializer = ts4.isAsExpression(property.initializer) ? property.initializer.expression : property.initializer;
|
|
805
|
+
if (!ts4.isCallExpression(initializer))
|
|
1015
806
|
return null;
|
|
1016
807
|
return expressionName(initializer.expression);
|
|
1017
808
|
};
|
|
1018
|
-
var priorityOf = (fieldName) => {
|
|
1019
|
-
const priority = fieldOrderingPriority.indexOf(fieldName);
|
|
1020
|
-
return priority < 0 ? null : priority;
|
|
1021
|
-
};
|
|
1022
|
-
var insertionIndexForFieldOrder = (fieldNames, newFieldName) => {
|
|
1023
|
-
const newPriority = priorityOf(newFieldName);
|
|
1024
|
-
if (newPriority !== null) {
|
|
1025
|
-
const greaterPriorityIndex = fieldNames.findIndex((name) => {
|
|
1026
|
-
const existingPriority = priorityOf(name);
|
|
1027
|
-
return existingPriority !== null && existingPriority > newPriority;
|
|
1028
|
-
});
|
|
1029
|
-
if (greaterPriorityIndex >= 0)
|
|
1030
|
-
return greaterPriorityIndex;
|
|
1031
|
-
const lastPriorityIndex = fieldNames.reduce((lastIndex, name, index) => {
|
|
1032
|
-
const existingPriority = priorityOf(name);
|
|
1033
|
-
return existingPriority !== null ? index : lastIndex;
|
|
1034
|
-
}, -1);
|
|
1035
|
-
return lastPriorityIndex + 1;
|
|
1036
|
-
}
|
|
1037
|
-
const lastNonPriorityIndex = fieldNames.reduce((lastIndex, name, index) => priorityOf(name) === null ? index : lastIndex, -1);
|
|
1038
|
-
return lastNonPriorityIndex >= 0 ? lastNonPriorityIndex + 1 : fieldNames.length;
|
|
1039
|
-
};
|
|
1040
|
-
var insertOrderedFieldLine = (content, locator, fieldName, line, options) => {
|
|
1041
|
-
if (locator.fields.some((field) => field.name === fieldName))
|
|
1042
|
-
return content;
|
|
1043
|
-
const insertIndex = insertionIndexForFieldOrder(locator.fields.map((field) => field.name), fieldName);
|
|
1044
|
-
const formattedLine = line.trim();
|
|
1045
|
-
if (locator.fields.length === 0) {
|
|
1046
|
-
return spliceText(content, locator.objectStart, locator.objectEnd, `{
|
|
1047
|
-
${options.fieldIndent}${formattedLine}
|
|
1048
|
-
${options.closingIndent}}`);
|
|
1049
|
-
}
|
|
1050
|
-
const beforeField = locator.fields[insertIndex];
|
|
1051
|
-
if (beforeField) {
|
|
1052
|
-
const leadingComments = ts2.getLeadingCommentRanges(content, beforeField.fullStart) ?? [];
|
|
1053
|
-
const insertAt = lineStartAt(content, leadingComments[0]?.pos ?? beforeField.start);
|
|
1054
|
-
const indent = lineIndentAt(content, beforeField.start) || options.fieldIndent;
|
|
1055
|
-
return spliceText(content, insertAt, insertAt, `${indent}${formattedLine}
|
|
1056
|
-
`);
|
|
1057
|
-
}
|
|
1058
|
-
const afterField = locator.fields[locator.fields.length - 1];
|
|
1059
|
-
const insertAt = lineEndAt(content, afterField.end);
|
|
1060
|
-
const indent = lineIndentAt(content, afterField.start) || options.fieldIndent;
|
|
1061
|
-
return spliceText(content, insertAt, insertAt, `${indent}${formattedLine}
|
|
1062
|
-
`);
|
|
1063
|
-
};
|
|
1064
809
|
var viaBuilderParameterName = (content, className) => {
|
|
1065
810
|
const source = sourceFileFor("constant.ts", content);
|
|
1066
811
|
let builderName = null;
|
|
1067
812
|
const visit = (node) => {
|
|
1068
813
|
if (builderName !== null)
|
|
1069
814
|
return;
|
|
1070
|
-
if (!
|
|
1071
|
-
|
|
815
|
+
if (!ts4.isClassDeclaration(node) || node.name?.text !== className) {
|
|
816
|
+
ts4.forEachChild(node, visit);
|
|
1072
817
|
return;
|
|
1073
818
|
}
|
|
1074
819
|
const viaCall = heritageCall(node);
|
|
1075
|
-
const callback = viaCall?.arguments.find((arg) =>
|
|
1076
|
-
if (callback && (
|
|
820
|
+
const callback = viaCall?.arguments.find((arg) => ts4.isArrowFunction(arg) || ts4.isFunctionExpression(arg));
|
|
821
|
+
if (callback && (ts4.isArrowFunction(callback) || ts4.isFunctionExpression(callback))) {
|
|
1077
822
|
builderName = nodeName(callback.parameters[0]?.name);
|
|
1078
823
|
}
|
|
1079
824
|
};
|
|
1080
|
-
|
|
825
|
+
ts4.forEachChild(source, visit);
|
|
1081
826
|
return builderName;
|
|
1082
827
|
};
|
|
1083
828
|
var inspectConstantStructure = (content, className, moduleClassName) => {
|
|
@@ -1088,12 +833,12 @@ var inspectConstantStructure = (content, className, moduleClassName) => {
|
|
|
1088
833
|
const fields = [];
|
|
1089
834
|
if (inputObject) {
|
|
1090
835
|
const visit = (node) => {
|
|
1091
|
-
if (!
|
|
1092
|
-
|
|
836
|
+
if (!ts4.isClassDeclaration(node) || node.name?.text !== className) {
|
|
837
|
+
ts4.forEachChild(node, visit);
|
|
1093
838
|
return;
|
|
1094
839
|
}
|
|
1095
840
|
const viaCall = heritageCall(node);
|
|
1096
|
-
const callback = viaCall?.arguments.find((arg) =>
|
|
841
|
+
const callback = viaCall?.arguments.find((arg) => ts4.isArrowFunction(arg) || ts4.isFunctionExpression(arg));
|
|
1097
842
|
const objectLiteral = callback ? firstObjectReturnedByArrow(callback) : null;
|
|
1098
843
|
if (!objectLiteral)
|
|
1099
844
|
return;
|
|
@@ -1104,7 +849,7 @@ var inspectConstantStructure = (content, className, moduleClassName) => {
|
|
|
1104
849
|
return { name, expressionBuilder: fieldExpressionBuilder(property) };
|
|
1105
850
|
}).filter((field) => field !== null));
|
|
1106
851
|
};
|
|
1107
|
-
|
|
852
|
+
ts4.forEachChild(source, visit);
|
|
1108
853
|
}
|
|
1109
854
|
return {
|
|
1110
855
|
parseValid: !hasParseDiagnostics(source),
|
|
@@ -1115,17 +860,6 @@ var inspectConstantStructure = (content, className, moduleClassName) => {
|
|
|
1115
860
|
baseImports: baseImport?.names ?? []
|
|
1116
861
|
};
|
|
1117
862
|
};
|
|
1118
|
-
var inspectDictionaryStructure = (content, moduleClassName) => {
|
|
1119
|
-
const source = sourceFileFor("dictionary.ts", content);
|
|
1120
|
-
const modelObject = findDictionaryModelObject(source, moduleClassName);
|
|
1121
|
-
return {
|
|
1122
|
-
parseValid: !hasParseDiagnostics(source),
|
|
1123
|
-
modelObjectFound: modelObject !== null,
|
|
1124
|
-
chainOrderValid: modelObject ? dictionaryChainOrderValid(modelObject.chainMethods) : false,
|
|
1125
|
-
chainMethods: modelObject?.chainMethods ?? [],
|
|
1126
|
-
fields: modelObject?.fields.map((field) => field.name) ?? []
|
|
1127
|
-
};
|
|
1128
|
-
};
|
|
1129
863
|
var insertIntoObject = (content, className, line) => {
|
|
1130
864
|
const fieldName = /^([A-Za-z_$][\w$]*)\s*:/.exec(line.trim())?.[1];
|
|
1131
865
|
if (!fieldName)
|
|
@@ -1150,56 +884,149 @@ ${nextFields.map((field) => ` ${JSON.stringify(field)},`).join(`
|
|
|
1150
884
|
] as const`;
|
|
1151
885
|
return spliceText(content, locator.projectionStart, locator.projectionEnd, nextArray);
|
|
1152
886
|
};
|
|
1153
|
-
var
|
|
1154
|
-
content
|
|
1155
|
-
moduleName,
|
|
1156
|
-
moduleClassName,
|
|
1157
|
-
fieldName,
|
|
1158
|
-
component
|
|
1159
|
-
}) => {
|
|
1160
|
-
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`))
|
|
1161
889
|
return content;
|
|
1162
|
-
const
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
return null;
|
|
1168
|
-
const fieldSetter = `st.do.set${moduleComponentName(fieldName)}On${moduleClassName}`;
|
|
1169
|
-
const fieldBlock = ` <${component}
|
|
1170
|
-
label={l("${moduleName}.${fieldName}")}
|
|
1171
|
-
desc={l("${moduleName}.${fieldName}.desc")}
|
|
1172
|
-
value={${formName}.${fieldName}}
|
|
1173
|
-
onChange={${fieldSetter}}
|
|
1174
|
-
/>
|
|
890
|
+
const enumClass = `export class ${enumClassName} extends enumOf("${enumName}", [
|
|
891
|
+
${values.map((value) => ` ${JSON.stringify(value)},`).join(`
|
|
892
|
+
`)}
|
|
893
|
+
] as const) {}
|
|
894
|
+
|
|
1175
895
|
`;
|
|
1176
|
-
|
|
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)}`;
|
|
1177
901
|
};
|
|
1178
|
-
var
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
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];
|
|
1185
968
|
}
|
|
1186
|
-
|
|
1187
|
-
|
|
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;
|
|
1188
1019
|
};
|
|
1189
|
-
var
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
if (firstClassIndex < 0)
|
|
1200
|
-
return `${content}
|
|
1201
|
-
${enumClass}`;
|
|
1202
|
-
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
|
+
};
|
|
1203
1030
|
};
|
|
1204
1031
|
var dictionaryModelFieldLine = (fieldName) => {
|
|
1205
1032
|
const label = bilingualLabelForField(fieldName);
|
|
@@ -1216,12 +1043,6 @@ var insertDictionaryModelField = (content, moduleClassName, fieldName) => {
|
|
|
1216
1043
|
closingIndent: " "
|
|
1217
1044
|
});
|
|
1218
1045
|
};
|
|
1219
|
-
var hasConstantInputField = (content, className, fieldName) => {
|
|
1220
|
-
const source = sourceFileFor("constant.ts", content);
|
|
1221
|
-
if (hasParseDiagnostics(source))
|
|
1222
|
-
return false;
|
|
1223
|
-
return findConstantInputObject(source, className)?.fields.some((field) => field.name === fieldName) ?? false;
|
|
1224
|
-
};
|
|
1225
1046
|
var hasDictionaryModelField = (content, moduleClassName, fieldName) => {
|
|
1226
1047
|
const source = sourceFileFor("dictionary.ts", content);
|
|
1227
1048
|
if (hasParseDiagnostics(source))
|
|
@@ -1239,28 +1060,16 @@ var insertDictionaryEndpointEntry = (content, moduleClassName, entryName, entryT
|
|
|
1239
1060
|
return null;
|
|
1240
1061
|
return insertOrderedFieldLine(content, locator, entryName, entryText, { fieldIndent: " ", closingIndent: " " });
|
|
1241
1062
|
};
|
|
1242
|
-
var ensureConstantTypeImport = (content, constantPath, typeName) => {
|
|
1243
|
-
if (new RegExp(`import type \\{[^}]*\\b${typeName}\\b[^}]*\\} from "${constantPath}";`).test(content))
|
|
1244
|
-
return content;
|
|
1245
|
-
const importPattern = new RegExp(`import type \\{ ([^}]+) \\} from "${constantPath}";`);
|
|
1246
|
-
const existingImport = content.match(importPattern);
|
|
1247
|
-
if (existingImport !== null) {
|
|
1248
|
-
const names = existingImport[1]?.split(",").map((name) => name.trim()) ?? [];
|
|
1249
|
-
return content.replace(existingImport[0], `import type { ${[...names, typeName].sort().join(", ")} } from "${constantPath}";`);
|
|
1250
|
-
}
|
|
1251
|
-
return `import type { ${typeName} } from "${constantPath}";
|
|
1252
|
-
${content}`;
|
|
1253
|
-
};
|
|
1254
1063
|
var dictionaryChainOf = (node) => {
|
|
1255
|
-
if (
|
|
1064
|
+
if (ts5.isCallExpression(node) && outermostFluentCall(node) === node && protectedDictionaryChainOrder.some((method) => chainMethodsForCall(node).includes(method)))
|
|
1256
1065
|
return node;
|
|
1257
|
-
return
|
|
1066
|
+
return ts5.forEachChild(node, dictionaryChainOf);
|
|
1258
1067
|
};
|
|
1259
1068
|
var chainMethodNames = (call) => {
|
|
1260
|
-
if (!
|
|
1069
|
+
if (!ts5.isCallExpression(call) || !ts5.isPropertyAccessExpression(call.expression))
|
|
1261
1070
|
return [];
|
|
1262
1071
|
const name = call.expression.name;
|
|
1263
|
-
return [...chainMethodNames(call.expression.expression), ...
|
|
1072
|
+
return [...chainMethodNames(call.expression.expression), ...ts5.isIdentifier(name) ? [name] : []];
|
|
1264
1073
|
};
|
|
1265
1074
|
var insertDictionaryEnum = (content, enumClassName, enumName, values) => {
|
|
1266
1075
|
if (content.includes(`.enum<${enumClassName}>("${enumName}"`))
|
|
@@ -1287,152 +1096,171 @@ ${enumBlock.trimEnd()}`);
|
|
|
1287
1096
|
return spliceText(content, dot, dot, `
|
|
1288
1097
|
${enumBlock}`);
|
|
1289
1098
|
};
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
var
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
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"
|
|
1302
1111
|
};
|
|
1303
|
-
|
|
1304
|
-
return found;
|
|
1305
|
-
};
|
|
1306
|
-
var firstHeritageCall = (node) => {
|
|
1307
|
-
const expression = (node.heritageClauses?.flatMap((clause) => [...clause.types]) ?? [])[0]?.expression;
|
|
1308
|
-
return expression && ts2.isCallExpression(expression) ? expression : null;
|
|
1309
|
-
};
|
|
1310
|
-
var factoryArrowOf = (call) => {
|
|
1311
|
-
const arg = call.arguments.find((argument) => ts2.isArrowFunction(argument) || ts2.isFunctionExpression(argument));
|
|
1312
|
-
return arg && (ts2.isArrowFunction(arg) || ts2.isFunctionExpression(arg)) ? arg : null;
|
|
1112
|
+
return normalizedTypes[typeName.toLowerCase()] ?? typeName;
|
|
1313
1113
|
};
|
|
1314
|
-
var
|
|
1315
|
-
|
|
1316
|
-
|
|
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;
|
|
1317
1130
|
};
|
|
1318
|
-
var
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
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;
|
|
1325
1138
|
};
|
|
1326
|
-
var
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
if (
|
|
1139
|
+
var dateDefault = (rawDefault) => {
|
|
1140
|
+
if (typeof rawDefault === "number" && Number.isFinite(rawDefault))
|
|
1141
|
+
return `() => dayjs(${rawDefault})`;
|
|
1142
|
+
if (typeof rawDefault !== "string")
|
|
1330
1143
|
return null;
|
|
1331
|
-
const
|
|
1332
|
-
if (
|
|
1144
|
+
const trimmed = rawDefault.trim();
|
|
1145
|
+
if (!trimmed)
|
|
1333
1146
|
return null;
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1147
|
+
if (trimmed === "now")
|
|
1148
|
+
return "() => dayjs()";
|
|
1149
|
+
if (!Number.isNaN(Date.parse(trimmed)))
|
|
1150
|
+
return `() => dayjs(${JSON.stringify(trimmed)})`;
|
|
1151
|
+
return null;
|
|
1339
1152
|
};
|
|
1340
|
-
var
|
|
1341
|
-
|
|
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 };
|
|
1342
1162
|
return {
|
|
1343
|
-
|
|
1344
|
-
|
|
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
|
+
}
|
|
1345
1173
|
};
|
|
1346
1174
|
}
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
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
|
+
};
|
|
1363
1191
|
}
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
return
|
|
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
|
-
|
|
1402
|
-
|
|
1403
|
-
fieldIndent: " ",
|
|
1404
|
-
closingIndent: ""
|
|
1405
|
-
});
|
|
1406
|
-
if (withEntry === content)
|
|
1407
|
-
return null;
|
|
1408
|
-
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
|
+
};
|
|
1409
1231
|
};
|
|
1410
|
-
var
|
|
1411
|
-
const
|
|
1412
|
-
const
|
|
1413
|
-
const
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
return [];
|
|
1418
|
-
if (expressionName(statement.expression.expression) !== "describe")
|
|
1419
|
-
return [];
|
|
1420
|
-
const callback = factoryArrowOf(statement.expression);
|
|
1421
|
-
return callback && ts2.isBlock(callback.body) ? [callback.body] : [];
|
|
1422
|
-
})[0];
|
|
1423
|
-
if (!body) {
|
|
1424
|
-
const block = [`describe(${JSON.stringify(describeTitle)}, () => {`, ...render(itName, " "), "});", ""];
|
|
1425
|
-
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) ?? [];
|
|
1426
1239
|
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
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
|
+
};
|
|
1436
1264
|
};
|
|
1437
1265
|
|
|
1438
1266
|
// pkgs/@akanjs/devkit/workflow/moduleIndex.ts
|
|
@@ -1469,7 +1297,7 @@ var parseDiagnosticsFor = (source, filePath) => {
|
|
|
1469
1297
|
return parseDiagnostics.map((diagnostic) => ({
|
|
1470
1298
|
severity: "error",
|
|
1471
1299
|
code: "module-index-typescript-parse-error",
|
|
1472
|
-
message: `TypeScript parse diagnostic TS${diagnostic.code} in ${filePath}: ${
|
|
1300
|
+
message: `TypeScript parse diagnostic TS${diagnostic.code} in ${filePath}: ${ts6.flattenDiagnosticMessageText(diagnostic.messageText, `
|
|
1473
1301
|
`)}`,
|
|
1474
1302
|
context: { target: filePath, paths: [filePath] }
|
|
1475
1303
|
}));
|
|
@@ -1488,32 +1316,32 @@ var spanFor = (source, file, node) => {
|
|
|
1488
1316
|
};
|
|
1489
1317
|
};
|
|
1490
1318
|
var expressionSummary = (expression) => {
|
|
1491
|
-
if (
|
|
1319
|
+
if (ts6.isAsExpression(expression))
|
|
1492
1320
|
return expressionSummary(expression.expression);
|
|
1493
|
-
if (
|
|
1321
|
+
if (ts6.isIdentifier(expression) || ts6.isPropertyAccessExpression(expression))
|
|
1494
1322
|
return expressionName(expression) ?? "expression";
|
|
1495
|
-
if (
|
|
1323
|
+
if (ts6.isArrayLiteralExpression(expression))
|
|
1496
1324
|
return "array-literal";
|
|
1497
|
-
if (
|
|
1325
|
+
if (ts6.isObjectLiteralExpression(expression))
|
|
1498
1326
|
return "object-literal";
|
|
1499
|
-
if (
|
|
1327
|
+
if (ts6.isStringLiteralLike(expression))
|
|
1500
1328
|
return "string-literal";
|
|
1501
|
-
if (
|
|
1329
|
+
if (ts6.isNumericLiteral(expression))
|
|
1502
1330
|
return "numeric-literal";
|
|
1503
|
-
if (expression.kind ===
|
|
1331
|
+
if (expression.kind === ts6.SyntaxKind.TrueKeyword || expression.kind === ts6.SyntaxKind.FalseKeyword) {
|
|
1504
1332
|
return "boolean-literal";
|
|
1505
1333
|
}
|
|
1506
|
-
if (
|
|
1334
|
+
if (ts6.isCallExpression(expression)) {
|
|
1507
1335
|
const callee = expressionName(expression.expression);
|
|
1508
1336
|
return callee ? `${callee}(...)` : "call-expression";
|
|
1509
1337
|
}
|
|
1510
|
-
return
|
|
1338
|
+
return ts6.SyntaxKind[expression.kind] ?? "expression";
|
|
1511
1339
|
};
|
|
1512
1340
|
var typeSummaryForInitializer = (initializer) => {
|
|
1513
1341
|
if (!initializer)
|
|
1514
1342
|
return;
|
|
1515
|
-
const expression =
|
|
1516
|
-
if (!
|
|
1343
|
+
const expression = ts6.isAsExpression(initializer) ? initializer.expression : initializer;
|
|
1344
|
+
if (!ts6.isCallExpression(expression))
|
|
1517
1345
|
return expressionSummary(expression);
|
|
1518
1346
|
const callee = expressionName(expression.expression);
|
|
1519
1347
|
const firstArg = expression.arguments[0];
|
|
@@ -1524,7 +1352,7 @@ var fieldsFromObject = (source, file, objectLiteral, kind) => objectLiteral.prop
|
|
|
1524
1352
|
const name = propertyName(property);
|
|
1525
1353
|
if (!name)
|
|
1526
1354
|
return null;
|
|
1527
|
-
const initializer =
|
|
1355
|
+
const initializer = ts6.isPropertyAssignment(property) ? property.initializer : undefined;
|
|
1528
1356
|
return {
|
|
1529
1357
|
name,
|
|
1530
1358
|
kind,
|
|
@@ -1545,8 +1373,8 @@ var parseConstantIndex = (filePath, content, moduleClassName) => {
|
|
|
1545
1373
|
let fields = [];
|
|
1546
1374
|
let lightProjection;
|
|
1547
1375
|
const visit = (node) => {
|
|
1548
|
-
if (!
|
|
1549
|
-
|
|
1376
|
+
if (!ts6.isClassDeclaration(node) || !node.name) {
|
|
1377
|
+
ts6.forEachChild(node, visit);
|
|
1550
1378
|
return;
|
|
1551
1379
|
}
|
|
1552
1380
|
const className = node.name.text;
|
|
@@ -1556,8 +1384,8 @@ var parseConstantIndex = (filePath, content, moduleClassName) => {
|
|
|
1556
1384
|
if (!viaCall)
|
|
1557
1385
|
return;
|
|
1558
1386
|
inputViaFound = true;
|
|
1559
|
-
const callback = viaCall.arguments.find((arg) =>
|
|
1560
|
-
if (callback && (
|
|
1387
|
+
const callback = viaCall.arguments.find((arg) => ts6.isArrowFunction(arg) || ts6.isFunctionExpression(arg));
|
|
1388
|
+
if (callback && (ts6.isArrowFunction(callback) || ts6.isFunctionExpression(callback))) {
|
|
1561
1389
|
inputBuilderFound = true;
|
|
1562
1390
|
builderName = nodeName(callback.parameters[0]?.name) ?? null;
|
|
1563
1391
|
const objectLiteral = firstObjectReturnedByArrow(callback);
|
|
@@ -1571,15 +1399,15 @@ var parseConstantIndex = (filePath, content, moduleClassName) => {
|
|
|
1571
1399
|
return;
|
|
1572
1400
|
if (className === `Light${moduleClassName}`) {
|
|
1573
1401
|
const projectionArg = viaCall.arguments.find((arg) => {
|
|
1574
|
-
const expression =
|
|
1575
|
-
return
|
|
1402
|
+
const expression = ts6.isAsExpression(arg) ? arg.expression : arg;
|
|
1403
|
+
return ts6.isArrayLiteralExpression(expression);
|
|
1576
1404
|
});
|
|
1577
|
-
const arrayLiteral = projectionArg ?
|
|
1578
|
-
if (arrayLiteral &&
|
|
1405
|
+
const arrayLiteral = projectionArg ? ts6.isAsExpression(projectionArg) ? projectionArg.expression : projectionArg : null;
|
|
1406
|
+
if (arrayLiteral && ts6.isArrayLiteralExpression(arrayLiteral)) {
|
|
1579
1407
|
lightProjection = {
|
|
1580
1408
|
className,
|
|
1581
1409
|
sourceSpan: spanFor(source, filePath, arrayLiteral),
|
|
1582
|
-
fields: arrayLiteral.elements.map((element, order) =>
|
|
1410
|
+
fields: arrayLiteral.elements.map((element, order) => ts6.isStringLiteralLike(element) ? {
|
|
1583
1411
|
name: element.text,
|
|
1584
1412
|
kind: "lightProjection",
|
|
1585
1413
|
order,
|
|
@@ -1590,7 +1418,7 @@ var parseConstantIndex = (filePath, content, moduleClassName) => {
|
|
|
1590
1418
|
}
|
|
1591
1419
|
}
|
|
1592
1420
|
};
|
|
1593
|
-
|
|
1421
|
+
ts6.forEachChild(source, visit);
|
|
1594
1422
|
if (!inputClass) {
|
|
1595
1423
|
diagnostics.push({
|
|
1596
1424
|
severity: "error",
|
|
@@ -1638,22 +1466,22 @@ var parseDictionaryIndex = (filePath, content, moduleClassName) => {
|
|
|
1638
1466
|
let index;
|
|
1639
1467
|
let modelFound = false;
|
|
1640
1468
|
const visit = (node) => {
|
|
1641
|
-
if (modelFound || !
|
|
1642
|
-
|
|
1469
|
+
if (modelFound || !ts6.isCallExpression(node)) {
|
|
1470
|
+
ts6.forEachChild(node, visit);
|
|
1643
1471
|
return;
|
|
1644
1472
|
}
|
|
1645
1473
|
if (callExpressionName(node) !== "model") {
|
|
1646
|
-
|
|
1474
|
+
ts6.forEachChild(node, visit);
|
|
1647
1475
|
return;
|
|
1648
1476
|
}
|
|
1649
1477
|
const typeArgument = node.typeArguments?.[0];
|
|
1650
1478
|
if (!typeArgument || typeArgument.getText(source) !== moduleClassName) {
|
|
1651
|
-
|
|
1479
|
+
ts6.forEachChild(node, visit);
|
|
1652
1480
|
return;
|
|
1653
1481
|
}
|
|
1654
1482
|
modelFound = true;
|
|
1655
|
-
const callback = node.arguments.find((arg) =>
|
|
1656
|
-
if (!callback || !
|
|
1483
|
+
const callback = node.arguments.find((arg) => ts6.isArrowFunction(arg) || ts6.isFunctionExpression(arg));
|
|
1484
|
+
if (!callback || !ts6.isArrowFunction(callback) && !ts6.isFunctionExpression(callback)) {
|
|
1657
1485
|
diagnostics.push({
|
|
1658
1486
|
severity: "error",
|
|
1659
1487
|
code: "module-index-dictionary-builder-missing",
|
|
@@ -1679,7 +1507,7 @@ var parseDictionaryIndex = (filePath, content, moduleClassName) => {
|
|
|
1679
1507
|
sourceSpan: spanFor(source, filePath, node)
|
|
1680
1508
|
};
|
|
1681
1509
|
};
|
|
1682
|
-
|
|
1510
|
+
ts6.forEachChild(source, visit);
|
|
1683
1511
|
return { index, diagnostics, modelFound };
|
|
1684
1512
|
};
|
|
1685
1513
|
var expectedFilesFor = (module) => {
|
|
@@ -1852,9 +1680,9 @@ var postApplyDiagnostic = (code, message, target, severity = "error") => ({
|
|
|
1852
1680
|
});
|
|
1853
1681
|
var sourceKindForPath = (filePath) => {
|
|
1854
1682
|
if (filePath.endsWith(".tsx"))
|
|
1855
|
-
return
|
|
1683
|
+
return ts7.ScriptKind.TSX;
|
|
1856
1684
|
if (filePath.endsWith(".ts"))
|
|
1857
|
-
return
|
|
1685
|
+
return ts7.ScriptKind.TS;
|
|
1858
1686
|
return null;
|
|
1859
1687
|
};
|
|
1860
1688
|
var checkPathCasing = async (workspace, filePath) => {
|
|
@@ -1882,7 +1710,7 @@ var checkTypeScriptSyntax = async (workspace, filePath) => {
|
|
|
1882
1710
|
if (!scriptKind)
|
|
1883
1711
|
return null;
|
|
1884
1712
|
const content = await workspace.readFile(filePath);
|
|
1885
|
-
const source =
|
|
1713
|
+
const source = ts7.createSourceFile(filePath, content, ts7.ScriptTarget.Latest, true, scriptKind);
|
|
1886
1714
|
const diagnostic = (source.parseDiagnostics ?? [])[0];
|
|
1887
1715
|
if (!diagnostic)
|
|
1888
1716
|
return null;
|
|
@@ -1890,7 +1718,7 @@ var checkTypeScriptSyntax = async (workspace, filePath) => {
|
|
|
1890
1718
|
const location = position ? `:${position.line + 1}:${position.character + 1}` : "";
|
|
1891
1719
|
return {
|
|
1892
1720
|
code: "workflow-post-apply-syntax-error",
|
|
1893
|
-
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, " ")}`
|
|
1894
1722
|
};
|
|
1895
1723
|
};
|
|
1896
1724
|
var checkChangedFile = async (workspace, file) => {
|
|
@@ -2311,7 +2139,7 @@ class WorkflowExecutor {
|
|
|
2311
2139
|
}
|
|
2312
2140
|
}
|
|
2313
2141
|
// pkgs/@akanjs/devkit/workflow/fieldType.ts
|
|
2314
|
-
import
|
|
2142
|
+
import ts8 from "typescript";
|
|
2315
2143
|
var builtInFieldTypes = new Set(["String", "Boolean", "Date", "Map"]);
|
|
2316
2144
|
var baseFieldTypes = new Set(["Int", "Float", "ID", "Any", "Binary", "ImageResult"]);
|
|
2317
2145
|
var fieldTypeReference = /^\[*([A-Za-z_$][\w$]*)((?:\.[A-Za-z_$][\w$]*)*)\]*$/;
|
|
@@ -2324,24 +2152,24 @@ var ensureBaseTypeImport = (content, typeName) => {
|
|
|
2324
2152
|
var valueNamesOf = (content) => {
|
|
2325
2153
|
const names = new Set;
|
|
2326
2154
|
for (const statement of sourceFileFor("source.ts", content).statements) {
|
|
2327
|
-
if (
|
|
2155
|
+
if (ts8.isImportDeclaration(statement)) {
|
|
2328
2156
|
const clause = statement.importClause;
|
|
2329
2157
|
if (!clause || clause.isTypeOnly)
|
|
2330
2158
|
continue;
|
|
2331
2159
|
if (clause.name)
|
|
2332
2160
|
names.add(clause.name.text);
|
|
2333
2161
|
const bindings = clause.namedBindings;
|
|
2334
|
-
if (bindings &&
|
|
2162
|
+
if (bindings && ts8.isNamespaceImport(bindings))
|
|
2335
2163
|
names.add(bindings.name.text);
|
|
2336
2164
|
else
|
|
2337
2165
|
for (const element of bindings?.elements ?? [])
|
|
2338
2166
|
if (!element.isTypeOnly)
|
|
2339
2167
|
names.add(element.name.text);
|
|
2340
|
-
} else if (
|
|
2168
|
+
} else if (ts8.isVariableStatement(statement)) {
|
|
2341
2169
|
for (const declaration of statement.declarationList.declarations)
|
|
2342
|
-
if (
|
|
2170
|
+
if (ts8.isIdentifier(declaration.name))
|
|
2343
2171
|
names.add(declaration.name.text);
|
|
2344
|
-
} else if ((
|
|
2172
|
+
} else if ((ts8.isClassDeclaration(statement) || ts8.isEnumDeclaration(statement) || ts8.isFunctionDeclaration(statement)) && statement.name)
|
|
2345
2173
|
names.add(statement.name.text);
|
|
2346
2174
|
}
|
|
2347
2175
|
return names;
|
|
@@ -2471,7 +2299,7 @@ class GuardCatalog {
|
|
|
2471
2299
|
// pkgs/@akanjs/devkit/workflow/keyRename.ts
|
|
2472
2300
|
import { readFile } from "fs/promises";
|
|
2473
2301
|
import path2 from "path";
|
|
2474
|
-
import
|
|
2302
|
+
import ts9 from "typescript";
|
|
2475
2303
|
var indexedPath = /^(apps|libs)\/(?!(?:.*\/)?(?:node_modules|dist|\.akan)\/).*\.tsx?$/;
|
|
2476
2304
|
var keyPattern = /^[a-z][A-Za-z0-9]*$/;
|
|
2477
2305
|
var slashed = (fileName) => fileName.replace(/\\/g, "/");
|
|
@@ -2500,7 +2328,7 @@ class KeyRename {
|
|
|
2500
2328
|
const sourceRelative = `${getSysRoot(sys)}/${family === "slice" ? paths.signal : paths.document}`;
|
|
2501
2329
|
const sourcePath = slashed(path2.join(root, sourceRelative));
|
|
2502
2330
|
const texts = new Map;
|
|
2503
|
-
const index = new AkanIndex({ ts:
|
|
2331
|
+
const index = new AkanIndex({ ts: ts9, root });
|
|
2504
2332
|
for (const relative of await workspace.getAllFiles("{apps,libs}/**/*.{ts,tsx}")) {
|
|
2505
2333
|
if (!indexedPath.test(slashed(relative)))
|
|
2506
2334
|
continue;
|
|
@@ -2721,6 +2549,138 @@ class MutationSource {
|
|
|
2721
2549
|
}
|
|
2722
2550
|
}
|
|
2723
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
|
+
|
|
2724
2684
|
// pkgs/@akanjs/devkit/workflow/mutationScaffold.ts
|
|
2725
2685
|
class MutationScaffold {
|
|
2726
2686
|
static #documentMethods = new Set(["isModified", "refresh", "remove", "save", "set", "toJSON", "toObject"]);
|
|
@@ -3921,4 +3881,76 @@ for (const candidate of toolingRolloutCandidates) {
|
|
|
3921
3881
|
if (isRestrictedCandidate(candidate))
|
|
3922
3882
|
restrictedCandidates.set(candidate.packageName, candidate);
|
|
3923
3883
|
}
|
|
3924
|
-
|
|
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 };
|