@kosdev-code/kos-codegen-core 0.1.0-next.780 → 0.1.0-next.782
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/index.js +77 -39
- package/index.js.map +1 -1
- package/index.mjs +77 -39
- package/index.mjs.map +1 -1
- package/lib/codegen-filesystem.d.ts.map +1 -1
- package/lib/generators/add-container-support/generate-add-container-support.d.ts.map +1 -1
- package/lib/generators/add-future-to-model/registration-transformer.d.ts.map +1 -1
- package/lib/generators/augment/ts-toolkit.d.ts.map +1 -1
- package/lib/generators/component/plugin-handlers/base.d.ts.map +1 -1
- package/lib/generators/component/plugin-handlers/custom-handler.d.ts.map +1 -1
- package/lib/generators/component/utils/validation.d.ts.map +1 -1
- package/lib/generators/describe/describe-model.d.ts.map +1 -1
- package/lib/generators/generate-container-model.d.ts +1 -0
- package/lib/generators/generate-container-model.d.ts.map +1 -1
- package/lib/generators/generate-context.d.ts.map +1 -1
- package/lib/generators/generate-hook.d.ts.map +1 -1
- package/lib/generators/generate-model.d.ts.map +1 -1
- package/lib/generators/member-mutators/add-computed.d.ts.map +1 -1
- package/lib/generators/member-mutators/add-config-property.d.ts.map +1 -1
- package/lib/generators/member-mutators/add-dependency.d.ts.map +1 -1
- package/lib/generators/member-mutators/add-model-effect.d.ts.map +1 -1
- package/lib/generators/member-mutators/add-property.d.ts.map +1 -1
- package/lib/generators/member-mutators/add-service-request.d.ts.map +1 -1
- package/lib/generators/member-mutators/add-topic-handler.d.ts.map +1 -1
- package/lib/generators/types/lookup-sdk-type.d.ts.map +1 -1
- package/lib/generators/update-model-index.d.ts.map +1 -1
- package/lib/generators/validate/validate-model.d.ts.map +1 -1
- package/lib/kos-config.d.ts.map +1 -1
- package/lib/project-discovery.d.ts.map +1 -1
- package/package.json +2 -2
- package/templates/kos-container-model/model/__nameDashCase__-model.ts.template +14 -7
package/index.mjs
CHANGED
|
@@ -585,6 +585,13 @@ function updateModelIndex(codegenFs, indexPath, modelPath) {
|
|
|
585
585
|
ts.ScriptTarget.Latest,
|
|
586
586
|
true
|
|
587
587
|
);
|
|
588
|
+
const alreadyExported = sourceFile.statements.some(
|
|
589
|
+
(st) => ts.isExportDeclaration(st) && st.moduleSpecifier !== void 0 && ts.isStringLiteral(st.moduleSpecifier) && st.moduleSpecifier.text === `./${modelPath}`
|
|
590
|
+
);
|
|
591
|
+
if (alreadyExported) {
|
|
592
|
+
logger.info(`Export for ${modelPath} already present in ${indexPath}`);
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
588
595
|
const exportDeclaration = ts.factory.createExportDeclaration(
|
|
589
596
|
void 0,
|
|
590
597
|
false,
|
|
@@ -646,7 +653,12 @@ function generateHook(codegenFs, templateDir, options, cwd, projects) {
|
|
|
646
653
|
generateFilesFromTemplates(
|
|
647
654
|
codegenFs,
|
|
648
655
|
templateDir,
|
|
649
|
-
path.join(
|
|
656
|
+
path.join(
|
|
657
|
+
projectRoot,
|
|
658
|
+
options.appDirectory,
|
|
659
|
+
"hooks",
|
|
660
|
+
normalized.nameDashCase
|
|
661
|
+
),
|
|
650
662
|
normalized
|
|
651
663
|
);
|
|
652
664
|
appendBarrelExport(
|
|
@@ -765,9 +777,7 @@ function generateContainerModel(codegenFs, templateDir, options, cwd, projects)
|
|
|
765
777
|
{ ...normalized, internal }
|
|
766
778
|
);
|
|
767
779
|
if (options.dataServices) {
|
|
768
|
-
logger.info(
|
|
769
|
-
`Generating data services for ${modelNameDashCase}`
|
|
770
|
-
);
|
|
780
|
+
logger.info(`Generating data services for ${modelNameDashCase}`);
|
|
771
781
|
generateFilesFromTemplates(
|
|
772
782
|
codegenFs,
|
|
773
783
|
path.join(templateDir, "services"),
|
|
@@ -873,9 +883,7 @@ function generateModel(params) {
|
|
|
873
883
|
const modelLocation = kosConfig?.generator?.defaults?.model?.folder || "";
|
|
874
884
|
const internal = !!kosConfig?.generator?.internal;
|
|
875
885
|
options.modelDirectory = options.modelDirectory || modelLocation;
|
|
876
|
-
logger.info(
|
|
877
|
-
`Generating model ${normalized.nameDashCase} in ${projectRoot}`
|
|
878
|
-
);
|
|
886
|
+
logger.info(`Generating model ${normalized.nameDashCase} in ${projectRoot}`);
|
|
879
887
|
generateFilesFromTemplates(
|
|
880
888
|
codegenFs,
|
|
881
889
|
path.join(modelTemplateDir, "model"),
|
|
@@ -1472,9 +1480,7 @@ class RegistrationFileTransformer {
|
|
|
1472
1480
|
const logger = getCodegenLogger();
|
|
1473
1481
|
const { registrationFilePath } = this.options;
|
|
1474
1482
|
if (!registrationFilePath || !this.codegenFs.exists(registrationFilePath)) {
|
|
1475
|
-
logger.warn(
|
|
1476
|
-
"Registration file not found, skipping registration updates"
|
|
1477
|
-
);
|
|
1483
|
+
logger.warn("Registration file not found, skipping registration updates");
|
|
1478
1484
|
return;
|
|
1479
1485
|
}
|
|
1480
1486
|
let content = this.codegenFs.read(registrationFilePath);
|
|
@@ -1666,9 +1672,7 @@ function ensureNamedImport(sourceFile, moduleSpecifier, names) {
|
|
|
1666
1672
|
}
|
|
1667
1673
|
}
|
|
1668
1674
|
function resolveSdkModuleSpecifier(sourceFile) {
|
|
1669
|
-
const decl = sourceFile.getImportDeclarations().find(
|
|
1670
|
-
(d) => d.getNamedImports().some((n) => n.getName() === "kosModel")
|
|
1671
|
-
);
|
|
1675
|
+
const decl = sourceFile.getImportDeclarations().find((d) => d.getNamedImports().some((n) => n.getName() === "kosModel"));
|
|
1672
1676
|
return decl?.getModuleSpecifierValue() ?? "@kosdev-code/kos-ui-sdk";
|
|
1673
1677
|
}
|
|
1674
1678
|
function getModelClass(sourceFile, preferName) {
|
|
@@ -1687,7 +1691,10 @@ function addClassDecorator(cls, name, opts) {
|
|
|
1687
1691
|
const decorators = cls.getDecorators();
|
|
1688
1692
|
const kosModelIdx = decorators.findIndex((d) => d.getName() === "kosModel");
|
|
1689
1693
|
const insertIdx = kosModelIdx >= 0 ? kosModelIdx + 1 : decorators.length;
|
|
1690
|
-
cls.insertDecorator(insertIdx, {
|
|
1694
|
+
cls.insertDecorator(insertIdx, {
|
|
1695
|
+
name: `${name}${typeArgs}`,
|
|
1696
|
+
arguments: args ? [args] : []
|
|
1697
|
+
});
|
|
1691
1698
|
}
|
|
1692
1699
|
function ensureDeclarationMerge(sourceFile, interfaceName, extendsExpr, typeParameters = []) {
|
|
1693
1700
|
const baseType = extendsExpr.split("<")[0].trim();
|
|
@@ -1719,7 +1726,9 @@ function addDecoratedMethod(cls, spec) {
|
|
|
1719
1726
|
name: spec.name,
|
|
1720
1727
|
isAsync: spec.isAsync,
|
|
1721
1728
|
returnType: spec.returnType,
|
|
1722
|
-
parameters: spec.parameters?.map((p) =>
|
|
1729
|
+
parameters: spec.parameters?.map((p) => {
|
|
1730
|
+
return { name: p.name, type: p.type };
|
|
1731
|
+
}),
|
|
1723
1732
|
statements: spec.statements,
|
|
1724
1733
|
decorators: [
|
|
1725
1734
|
{
|
|
@@ -1785,7 +1794,9 @@ function buildDecoratorArgs(options) {
|
|
|
1785
1794
|
top.push(`containerProperty: ${JSON.stringify(options.containerProperty)}`);
|
|
1786
1795
|
}
|
|
1787
1796
|
if (options.sortKey) {
|
|
1788
|
-
top.push(
|
|
1797
|
+
top.push(
|
|
1798
|
+
`containerOptions: { sortKey: ${JSON.stringify(options.sortKey)} }`
|
|
1799
|
+
);
|
|
1789
1800
|
}
|
|
1790
1801
|
return top.length ? `{ ${top.join(", ")} }` : "";
|
|
1791
1802
|
}
|
|
@@ -1842,7 +1853,9 @@ function addModelEffectToModel(codegenFs, options, projects) {
|
|
|
1842
1853
|
if (!codegenFs.exists(modelFilePath)) {
|
|
1843
1854
|
throw new Error(`Model file not found: ${modelFilePath}`);
|
|
1844
1855
|
}
|
|
1845
|
-
logger.info(
|
|
1856
|
+
logger.info(
|
|
1857
|
+
`Adding @kosModelEffect "${options.methodName}" to ${options.modelName}`
|
|
1858
|
+
);
|
|
1846
1859
|
transformSourceFile(codegenFs, modelFilePath, (sf) => {
|
|
1847
1860
|
const sdk = resolveSdkModuleSpecifier(sf);
|
|
1848
1861
|
ensureNamedImport(sf, sdk, [{ name: "kosModelEffect" }]);
|
|
@@ -1866,7 +1879,9 @@ function addDependencyToModel(codegenFs, options, projects) {
|
|
|
1866
1879
|
if (!codegenFs.exists(modelFilePath)) {
|
|
1867
1880
|
throw new Error(`Model file not found: ${modelFilePath}`);
|
|
1868
1881
|
}
|
|
1869
|
-
logger.info(
|
|
1882
|
+
logger.info(
|
|
1883
|
+
`Adding @kosDependency "${options.propertyName}" to ${options.modelName}`
|
|
1884
|
+
);
|
|
1870
1885
|
const argsParts = [`modelType: ${options.modelTypeRef}`];
|
|
1871
1886
|
if (options.id) argsParts.push(`id: ${JSON.stringify(options.id)}`);
|
|
1872
1887
|
transformSourceFile(codegenFs, modelFilePath, (sf) => {
|
|
@@ -1874,7 +1889,9 @@ function addDependencyToModel(codegenFs, options, projects) {
|
|
|
1874
1889
|
ensureNamedImport(sf, sdk, [{ name: "kosDependency" }]);
|
|
1875
1890
|
if (options.dependencyPackage) {
|
|
1876
1891
|
const named = [];
|
|
1877
|
-
const bean = options.modelTypeRef.match(
|
|
1892
|
+
const bean = options.modelTypeRef.match(
|
|
1893
|
+
/^([A-Za-z_$][\w$]*)\.type$/
|
|
1894
|
+
)?.[1];
|
|
1878
1895
|
if (bean) named.push({ name: bean });
|
|
1879
1896
|
const depType = options.dependencyType?.trim();
|
|
1880
1897
|
if (depType && /^[A-Za-z_$][\w$]*$/.test(depType) && !FRAMEWORK_TYPES.has(depType)) {
|
|
@@ -1900,7 +1917,9 @@ function addTopicHandlerToModel(codegenFs, options, projects) {
|
|
|
1900
1917
|
if (!codegenFs.exists(modelFilePath)) {
|
|
1901
1918
|
throw new Error(`Model file not found: ${modelFilePath}`);
|
|
1902
1919
|
}
|
|
1903
|
-
logger.info(
|
|
1920
|
+
logger.info(
|
|
1921
|
+
`Adding @kosTopicHandler "${options.handlerName}" to ${options.modelName}`
|
|
1922
|
+
);
|
|
1904
1923
|
const websocket = options.websocket ?? true;
|
|
1905
1924
|
const eventType = options.eventType || "unknown";
|
|
1906
1925
|
transformSourceFile(codegenFs, modelFilePath, (sf) => {
|
|
@@ -1926,7 +1945,9 @@ function addConfigPropertyToModel(codegenFs, options, projects) {
|
|
|
1926
1945
|
if (!codegenFs.exists(modelFilePath)) {
|
|
1927
1946
|
throw new Error(`Model file not found: ${modelFilePath}`);
|
|
1928
1947
|
}
|
|
1929
|
-
logger.info(
|
|
1948
|
+
logger.info(
|
|
1949
|
+
`Adding @kosConfigProperty "${options.propertyName}" to ${options.modelName}`
|
|
1950
|
+
);
|
|
1930
1951
|
const valueType = options.valueType || "unknown";
|
|
1931
1952
|
transformSourceFile(codegenFs, modelFilePath, (sf) => {
|
|
1932
1953
|
const sdk = resolveSdkModuleSpecifier(sf);
|
|
@@ -1967,7 +1988,9 @@ function addPropertyToModel(codegenFs, options, projects) {
|
|
|
1967
1988
|
}
|
|
1968
1989
|
const type = options.type || "string";
|
|
1969
1990
|
const initializer = options.initializer !== void 0 ? options.initializer : defaultInitializer(type);
|
|
1970
|
-
logger.info(
|
|
1991
|
+
logger.info(
|
|
1992
|
+
`Adding property "${options.propertyName}: ${type}" to ${options.modelName}`
|
|
1993
|
+
);
|
|
1971
1994
|
transformSourceFile(codegenFs, modelFilePath, (sf) => {
|
|
1972
1995
|
const cls = getModelClass(sf);
|
|
1973
1996
|
addPlainProperty(cls, {
|
|
@@ -1986,7 +2009,9 @@ function addComputedToModel(codegenFs, options, projects) {
|
|
|
1986
2009
|
if (!codegenFs.exists(modelFilePath)) {
|
|
1987
2010
|
throw new Error(`Model file not found: ${modelFilePath}`);
|
|
1988
2011
|
}
|
|
1989
|
-
logger.info(
|
|
2012
|
+
logger.info(
|
|
2013
|
+
`Adding computed getter "${options.name}" to ${options.modelName}`
|
|
2014
|
+
);
|
|
1990
2015
|
transformSourceFile(codegenFs, modelFilePath, (sf) => {
|
|
1991
2016
|
const cls = getModelClass(sf);
|
|
1992
2017
|
addGetter(cls, {
|
|
@@ -2047,7 +2072,9 @@ function addServiceRequestToModel(codegenFs, options, projects) {
|
|
|
2047
2072
|
`Adding @kosServiceRequest "${options.methodName}" (${method} ${options.servicePath}) to ${options.modelName}`
|
|
2048
2073
|
);
|
|
2049
2074
|
transformSourceFile(codegenFs, modelFilePath, (sf) => {
|
|
2050
|
-
ensureNamedImport(sf, serviceImport, [
|
|
2075
|
+
ensureNamedImport(sf, serviceImport, [
|
|
2076
|
+
{ name: "kosServiceRequest" }
|
|
2077
|
+
]);
|
|
2051
2078
|
ensureNamedImport(sf, resolveSdkModuleSpecifier(sf), [
|
|
2052
2079
|
{ name: "DependencyLifecycle" }
|
|
2053
2080
|
]);
|
|
@@ -2057,7 +2084,9 @@ function addServiceRequestToModel(codegenFs, options, projects) {
|
|
|
2057
2084
|
decoratorName: "kosServiceRequest",
|
|
2058
2085
|
decoratorArgsText: `{ path: ${JSON.stringify(
|
|
2059
2086
|
options.servicePath
|
|
2060
|
-
)}, method: ${JSON.stringify(
|
|
2087
|
+
)}, method: ${JSON.stringify(
|
|
2088
|
+
method
|
|
2089
|
+
)}, lifecycle: DependencyLifecycle.${lifecycle} }`,
|
|
2061
2090
|
returnType: "void",
|
|
2062
2091
|
statements: "// TODO: handle the typed response"
|
|
2063
2092
|
});
|
|
@@ -2079,7 +2108,9 @@ function validateModel(codegenFs, options, projects) {
|
|
|
2079
2108
|
throw new Error(`Model file not found: ${modelFilePath}`);
|
|
2080
2109
|
}
|
|
2081
2110
|
const project = new Project({ useInMemoryFileSystem: true });
|
|
2082
|
-
const sf = project.createSourceFile(modelFilePath, content, {
|
|
2111
|
+
const sf = project.createSourceFile(modelFilePath, content, {
|
|
2112
|
+
overwrite: true
|
|
2113
|
+
});
|
|
2083
2114
|
const findings = [];
|
|
2084
2115
|
const hasKosModel = sf.getClasses().some((c) => c.getDecorator("kosModel"));
|
|
2085
2116
|
if (!hasKosModel) {
|
|
@@ -2158,11 +2189,7 @@ function collectDecorated(cls, decoratorName) {
|
|
|
2158
2189
|
for (const m of cls.getMethods()) {
|
|
2159
2190
|
const dec = m.getDecorator(decoratorName);
|
|
2160
2191
|
if (dec) {
|
|
2161
|
-
visit(
|
|
2162
|
-
m.getName(),
|
|
2163
|
-
() => dec.getText(),
|
|
2164
|
-
m.getReturnTypeNode()?.getText()
|
|
2165
|
-
);
|
|
2192
|
+
visit(m.getName(), () => dec.getText(), m.getReturnTypeNode()?.getText());
|
|
2166
2193
|
}
|
|
2167
2194
|
}
|
|
2168
2195
|
for (const p of cls.getProperties()) {
|
|
@@ -2180,7 +2207,9 @@ function describeModel(codegenFs, options, projects) {
|
|
|
2180
2207
|
throw new Error(`Model file not found: ${modelFilePath}`);
|
|
2181
2208
|
}
|
|
2182
2209
|
const project = new Project({ useInMemoryFileSystem: true });
|
|
2183
|
-
const sf = project.createSourceFile(modelFilePath, content, {
|
|
2210
|
+
const sf = project.createSourceFile(modelFilePath, content, {
|
|
2211
|
+
overwrite: true
|
|
2212
|
+
});
|
|
2184
2213
|
let modelType;
|
|
2185
2214
|
const modelTypeDecl = sf.getVariableDeclaration("MODEL_TYPE");
|
|
2186
2215
|
if (modelTypeDecl) {
|
|
@@ -2255,7 +2284,10 @@ function resolveCandidateEntries(codegenFs, options, projects) {
|
|
|
2255
2284
|
const out = [];
|
|
2256
2285
|
if (options.entryFile) {
|
|
2257
2286
|
const abs = path.isAbsolute(options.entryFile) ? options.entryFile : path.join(root, options.entryFile);
|
|
2258
|
-
out.push({
|
|
2287
|
+
out.push({
|
|
2288
|
+
file: abs,
|
|
2289
|
+
mode: abs.endsWith(".d.ts") ? "declarations" : "source"
|
|
2290
|
+
});
|
|
2259
2291
|
}
|
|
2260
2292
|
const sdkProject = findProjectByName(root, sdkPackage, projects);
|
|
2261
2293
|
const sourceRoot = sdkProject ? sdkProject.sourceRoot || path.join(sdkProject.root, "src") : void 0;
|
|
@@ -2384,11 +2416,13 @@ function lookupSdkType(codegenFs, options, projects) {
|
|
|
2384
2416
|
mode: candidate.mode,
|
|
2385
2417
|
entryFile: path.relative(codegenFs.root, candidate.file),
|
|
2386
2418
|
triedEntries,
|
|
2387
|
-
declarations: decls.map((d) =>
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2419
|
+
declarations: decls.map((d) => {
|
|
2420
|
+
return {
|
|
2421
|
+
kind: d.getKindName(),
|
|
2422
|
+
file: path.relative(codegenFs.root, d.getSourceFile().getFilePath()),
|
|
2423
|
+
signature: signatureText(d)
|
|
2424
|
+
};
|
|
2425
|
+
})
|
|
2392
2426
|
};
|
|
2393
2427
|
}
|
|
2394
2428
|
return {
|
|
@@ -2851,7 +2885,11 @@ function validateOptions(codegenFs, options, projects) {
|
|
|
2851
2885
|
if (!options.appProject) {
|
|
2852
2886
|
throw new ValidationError("App project is required");
|
|
2853
2887
|
}
|
|
2854
|
-
const project = findProjectByName(
|
|
2888
|
+
const project = findProjectByName(
|
|
2889
|
+
codegenFs.root,
|
|
2890
|
+
options.appProject,
|
|
2891
|
+
projects
|
|
2892
|
+
);
|
|
2855
2893
|
if (!project) {
|
|
2856
2894
|
throw new ValidationError(
|
|
2857
2895
|
`Project "${options.appProject}" not found in workspace`
|