@kosdev-code/kos-codegen-core 0.1.0-next.780 → 0.1.0-next.781
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 +70 -39
- package/index.js.map +1 -1
- package/index.mjs +70 -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.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/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/index.mjs
CHANGED
|
@@ -646,7 +646,12 @@ function generateHook(codegenFs, templateDir, options, cwd, projects) {
|
|
|
646
646
|
generateFilesFromTemplates(
|
|
647
647
|
codegenFs,
|
|
648
648
|
templateDir,
|
|
649
|
-
path.join(
|
|
649
|
+
path.join(
|
|
650
|
+
projectRoot,
|
|
651
|
+
options.appDirectory,
|
|
652
|
+
"hooks",
|
|
653
|
+
normalized.nameDashCase
|
|
654
|
+
),
|
|
650
655
|
normalized
|
|
651
656
|
);
|
|
652
657
|
appendBarrelExport(
|
|
@@ -765,9 +770,7 @@ function generateContainerModel(codegenFs, templateDir, options, cwd, projects)
|
|
|
765
770
|
{ ...normalized, internal }
|
|
766
771
|
);
|
|
767
772
|
if (options.dataServices) {
|
|
768
|
-
logger.info(
|
|
769
|
-
`Generating data services for ${modelNameDashCase}`
|
|
770
|
-
);
|
|
773
|
+
logger.info(`Generating data services for ${modelNameDashCase}`);
|
|
771
774
|
generateFilesFromTemplates(
|
|
772
775
|
codegenFs,
|
|
773
776
|
path.join(templateDir, "services"),
|
|
@@ -873,9 +876,7 @@ function generateModel(params) {
|
|
|
873
876
|
const modelLocation = kosConfig?.generator?.defaults?.model?.folder || "";
|
|
874
877
|
const internal = !!kosConfig?.generator?.internal;
|
|
875
878
|
options.modelDirectory = options.modelDirectory || modelLocation;
|
|
876
|
-
logger.info(
|
|
877
|
-
`Generating model ${normalized.nameDashCase} in ${projectRoot}`
|
|
878
|
-
);
|
|
879
|
+
logger.info(`Generating model ${normalized.nameDashCase} in ${projectRoot}`);
|
|
879
880
|
generateFilesFromTemplates(
|
|
880
881
|
codegenFs,
|
|
881
882
|
path.join(modelTemplateDir, "model"),
|
|
@@ -1472,9 +1473,7 @@ class RegistrationFileTransformer {
|
|
|
1472
1473
|
const logger = getCodegenLogger();
|
|
1473
1474
|
const { registrationFilePath } = this.options;
|
|
1474
1475
|
if (!registrationFilePath || !this.codegenFs.exists(registrationFilePath)) {
|
|
1475
|
-
logger.warn(
|
|
1476
|
-
"Registration file not found, skipping registration updates"
|
|
1477
|
-
);
|
|
1476
|
+
logger.warn("Registration file not found, skipping registration updates");
|
|
1478
1477
|
return;
|
|
1479
1478
|
}
|
|
1480
1479
|
let content = this.codegenFs.read(registrationFilePath);
|
|
@@ -1666,9 +1665,7 @@ function ensureNamedImport(sourceFile, moduleSpecifier, names) {
|
|
|
1666
1665
|
}
|
|
1667
1666
|
}
|
|
1668
1667
|
function resolveSdkModuleSpecifier(sourceFile) {
|
|
1669
|
-
const decl = sourceFile.getImportDeclarations().find(
|
|
1670
|
-
(d) => d.getNamedImports().some((n) => n.getName() === "kosModel")
|
|
1671
|
-
);
|
|
1668
|
+
const decl = sourceFile.getImportDeclarations().find((d) => d.getNamedImports().some((n) => n.getName() === "kosModel"));
|
|
1672
1669
|
return decl?.getModuleSpecifierValue() ?? "@kosdev-code/kos-ui-sdk";
|
|
1673
1670
|
}
|
|
1674
1671
|
function getModelClass(sourceFile, preferName) {
|
|
@@ -1687,7 +1684,10 @@ function addClassDecorator(cls, name, opts) {
|
|
|
1687
1684
|
const decorators = cls.getDecorators();
|
|
1688
1685
|
const kosModelIdx = decorators.findIndex((d) => d.getName() === "kosModel");
|
|
1689
1686
|
const insertIdx = kosModelIdx >= 0 ? kosModelIdx + 1 : decorators.length;
|
|
1690
|
-
cls.insertDecorator(insertIdx, {
|
|
1687
|
+
cls.insertDecorator(insertIdx, {
|
|
1688
|
+
name: `${name}${typeArgs}`,
|
|
1689
|
+
arguments: args ? [args] : []
|
|
1690
|
+
});
|
|
1691
1691
|
}
|
|
1692
1692
|
function ensureDeclarationMerge(sourceFile, interfaceName, extendsExpr, typeParameters = []) {
|
|
1693
1693
|
const baseType = extendsExpr.split("<")[0].trim();
|
|
@@ -1719,7 +1719,9 @@ function addDecoratedMethod(cls, spec) {
|
|
|
1719
1719
|
name: spec.name,
|
|
1720
1720
|
isAsync: spec.isAsync,
|
|
1721
1721
|
returnType: spec.returnType,
|
|
1722
|
-
parameters: spec.parameters?.map((p) =>
|
|
1722
|
+
parameters: spec.parameters?.map((p) => {
|
|
1723
|
+
return { name: p.name, type: p.type };
|
|
1724
|
+
}),
|
|
1723
1725
|
statements: spec.statements,
|
|
1724
1726
|
decorators: [
|
|
1725
1727
|
{
|
|
@@ -1785,7 +1787,9 @@ function buildDecoratorArgs(options) {
|
|
|
1785
1787
|
top.push(`containerProperty: ${JSON.stringify(options.containerProperty)}`);
|
|
1786
1788
|
}
|
|
1787
1789
|
if (options.sortKey) {
|
|
1788
|
-
top.push(
|
|
1790
|
+
top.push(
|
|
1791
|
+
`containerOptions: { sortKey: ${JSON.stringify(options.sortKey)} }`
|
|
1792
|
+
);
|
|
1789
1793
|
}
|
|
1790
1794
|
return top.length ? `{ ${top.join(", ")} }` : "";
|
|
1791
1795
|
}
|
|
@@ -1842,7 +1846,9 @@ function addModelEffectToModel(codegenFs, options, projects) {
|
|
|
1842
1846
|
if (!codegenFs.exists(modelFilePath)) {
|
|
1843
1847
|
throw new Error(`Model file not found: ${modelFilePath}`);
|
|
1844
1848
|
}
|
|
1845
|
-
logger.info(
|
|
1849
|
+
logger.info(
|
|
1850
|
+
`Adding @kosModelEffect "${options.methodName}" to ${options.modelName}`
|
|
1851
|
+
);
|
|
1846
1852
|
transformSourceFile(codegenFs, modelFilePath, (sf) => {
|
|
1847
1853
|
const sdk = resolveSdkModuleSpecifier(sf);
|
|
1848
1854
|
ensureNamedImport(sf, sdk, [{ name: "kosModelEffect" }]);
|
|
@@ -1866,7 +1872,9 @@ function addDependencyToModel(codegenFs, options, projects) {
|
|
|
1866
1872
|
if (!codegenFs.exists(modelFilePath)) {
|
|
1867
1873
|
throw new Error(`Model file not found: ${modelFilePath}`);
|
|
1868
1874
|
}
|
|
1869
|
-
logger.info(
|
|
1875
|
+
logger.info(
|
|
1876
|
+
`Adding @kosDependency "${options.propertyName}" to ${options.modelName}`
|
|
1877
|
+
);
|
|
1870
1878
|
const argsParts = [`modelType: ${options.modelTypeRef}`];
|
|
1871
1879
|
if (options.id) argsParts.push(`id: ${JSON.stringify(options.id)}`);
|
|
1872
1880
|
transformSourceFile(codegenFs, modelFilePath, (sf) => {
|
|
@@ -1874,7 +1882,9 @@ function addDependencyToModel(codegenFs, options, projects) {
|
|
|
1874
1882
|
ensureNamedImport(sf, sdk, [{ name: "kosDependency" }]);
|
|
1875
1883
|
if (options.dependencyPackage) {
|
|
1876
1884
|
const named = [];
|
|
1877
|
-
const bean = options.modelTypeRef.match(
|
|
1885
|
+
const bean = options.modelTypeRef.match(
|
|
1886
|
+
/^([A-Za-z_$][\w$]*)\.type$/
|
|
1887
|
+
)?.[1];
|
|
1878
1888
|
if (bean) named.push({ name: bean });
|
|
1879
1889
|
const depType = options.dependencyType?.trim();
|
|
1880
1890
|
if (depType && /^[A-Za-z_$][\w$]*$/.test(depType) && !FRAMEWORK_TYPES.has(depType)) {
|
|
@@ -1900,7 +1910,9 @@ function addTopicHandlerToModel(codegenFs, options, projects) {
|
|
|
1900
1910
|
if (!codegenFs.exists(modelFilePath)) {
|
|
1901
1911
|
throw new Error(`Model file not found: ${modelFilePath}`);
|
|
1902
1912
|
}
|
|
1903
|
-
logger.info(
|
|
1913
|
+
logger.info(
|
|
1914
|
+
`Adding @kosTopicHandler "${options.handlerName}" to ${options.modelName}`
|
|
1915
|
+
);
|
|
1904
1916
|
const websocket = options.websocket ?? true;
|
|
1905
1917
|
const eventType = options.eventType || "unknown";
|
|
1906
1918
|
transformSourceFile(codegenFs, modelFilePath, (sf) => {
|
|
@@ -1926,7 +1938,9 @@ function addConfigPropertyToModel(codegenFs, options, projects) {
|
|
|
1926
1938
|
if (!codegenFs.exists(modelFilePath)) {
|
|
1927
1939
|
throw new Error(`Model file not found: ${modelFilePath}`);
|
|
1928
1940
|
}
|
|
1929
|
-
logger.info(
|
|
1941
|
+
logger.info(
|
|
1942
|
+
`Adding @kosConfigProperty "${options.propertyName}" to ${options.modelName}`
|
|
1943
|
+
);
|
|
1930
1944
|
const valueType = options.valueType || "unknown";
|
|
1931
1945
|
transformSourceFile(codegenFs, modelFilePath, (sf) => {
|
|
1932
1946
|
const sdk = resolveSdkModuleSpecifier(sf);
|
|
@@ -1967,7 +1981,9 @@ function addPropertyToModel(codegenFs, options, projects) {
|
|
|
1967
1981
|
}
|
|
1968
1982
|
const type = options.type || "string";
|
|
1969
1983
|
const initializer = options.initializer !== void 0 ? options.initializer : defaultInitializer(type);
|
|
1970
|
-
logger.info(
|
|
1984
|
+
logger.info(
|
|
1985
|
+
`Adding property "${options.propertyName}: ${type}" to ${options.modelName}`
|
|
1986
|
+
);
|
|
1971
1987
|
transformSourceFile(codegenFs, modelFilePath, (sf) => {
|
|
1972
1988
|
const cls = getModelClass(sf);
|
|
1973
1989
|
addPlainProperty(cls, {
|
|
@@ -1986,7 +2002,9 @@ function addComputedToModel(codegenFs, options, projects) {
|
|
|
1986
2002
|
if (!codegenFs.exists(modelFilePath)) {
|
|
1987
2003
|
throw new Error(`Model file not found: ${modelFilePath}`);
|
|
1988
2004
|
}
|
|
1989
|
-
logger.info(
|
|
2005
|
+
logger.info(
|
|
2006
|
+
`Adding computed getter "${options.name}" to ${options.modelName}`
|
|
2007
|
+
);
|
|
1990
2008
|
transformSourceFile(codegenFs, modelFilePath, (sf) => {
|
|
1991
2009
|
const cls = getModelClass(sf);
|
|
1992
2010
|
addGetter(cls, {
|
|
@@ -2047,7 +2065,9 @@ function addServiceRequestToModel(codegenFs, options, projects) {
|
|
|
2047
2065
|
`Adding @kosServiceRequest "${options.methodName}" (${method} ${options.servicePath}) to ${options.modelName}`
|
|
2048
2066
|
);
|
|
2049
2067
|
transformSourceFile(codegenFs, modelFilePath, (sf) => {
|
|
2050
|
-
ensureNamedImport(sf, serviceImport, [
|
|
2068
|
+
ensureNamedImport(sf, serviceImport, [
|
|
2069
|
+
{ name: "kosServiceRequest" }
|
|
2070
|
+
]);
|
|
2051
2071
|
ensureNamedImport(sf, resolveSdkModuleSpecifier(sf), [
|
|
2052
2072
|
{ name: "DependencyLifecycle" }
|
|
2053
2073
|
]);
|
|
@@ -2057,7 +2077,9 @@ function addServiceRequestToModel(codegenFs, options, projects) {
|
|
|
2057
2077
|
decoratorName: "kosServiceRequest",
|
|
2058
2078
|
decoratorArgsText: `{ path: ${JSON.stringify(
|
|
2059
2079
|
options.servicePath
|
|
2060
|
-
)}, method: ${JSON.stringify(
|
|
2080
|
+
)}, method: ${JSON.stringify(
|
|
2081
|
+
method
|
|
2082
|
+
)}, lifecycle: DependencyLifecycle.${lifecycle} }`,
|
|
2061
2083
|
returnType: "void",
|
|
2062
2084
|
statements: "// TODO: handle the typed response"
|
|
2063
2085
|
});
|
|
@@ -2079,7 +2101,9 @@ function validateModel(codegenFs, options, projects) {
|
|
|
2079
2101
|
throw new Error(`Model file not found: ${modelFilePath}`);
|
|
2080
2102
|
}
|
|
2081
2103
|
const project = new Project({ useInMemoryFileSystem: true });
|
|
2082
|
-
const sf = project.createSourceFile(modelFilePath, content, {
|
|
2104
|
+
const sf = project.createSourceFile(modelFilePath, content, {
|
|
2105
|
+
overwrite: true
|
|
2106
|
+
});
|
|
2083
2107
|
const findings = [];
|
|
2084
2108
|
const hasKosModel = sf.getClasses().some((c) => c.getDecorator("kosModel"));
|
|
2085
2109
|
if (!hasKosModel) {
|
|
@@ -2158,11 +2182,7 @@ function collectDecorated(cls, decoratorName) {
|
|
|
2158
2182
|
for (const m of cls.getMethods()) {
|
|
2159
2183
|
const dec = m.getDecorator(decoratorName);
|
|
2160
2184
|
if (dec) {
|
|
2161
|
-
visit(
|
|
2162
|
-
m.getName(),
|
|
2163
|
-
() => dec.getText(),
|
|
2164
|
-
m.getReturnTypeNode()?.getText()
|
|
2165
|
-
);
|
|
2185
|
+
visit(m.getName(), () => dec.getText(), m.getReturnTypeNode()?.getText());
|
|
2166
2186
|
}
|
|
2167
2187
|
}
|
|
2168
2188
|
for (const p of cls.getProperties()) {
|
|
@@ -2180,7 +2200,9 @@ function describeModel(codegenFs, options, projects) {
|
|
|
2180
2200
|
throw new Error(`Model file not found: ${modelFilePath}`);
|
|
2181
2201
|
}
|
|
2182
2202
|
const project = new Project({ useInMemoryFileSystem: true });
|
|
2183
|
-
const sf = project.createSourceFile(modelFilePath, content, {
|
|
2203
|
+
const sf = project.createSourceFile(modelFilePath, content, {
|
|
2204
|
+
overwrite: true
|
|
2205
|
+
});
|
|
2184
2206
|
let modelType;
|
|
2185
2207
|
const modelTypeDecl = sf.getVariableDeclaration("MODEL_TYPE");
|
|
2186
2208
|
if (modelTypeDecl) {
|
|
@@ -2255,7 +2277,10 @@ function resolveCandidateEntries(codegenFs, options, projects) {
|
|
|
2255
2277
|
const out = [];
|
|
2256
2278
|
if (options.entryFile) {
|
|
2257
2279
|
const abs = path.isAbsolute(options.entryFile) ? options.entryFile : path.join(root, options.entryFile);
|
|
2258
|
-
out.push({
|
|
2280
|
+
out.push({
|
|
2281
|
+
file: abs,
|
|
2282
|
+
mode: abs.endsWith(".d.ts") ? "declarations" : "source"
|
|
2283
|
+
});
|
|
2259
2284
|
}
|
|
2260
2285
|
const sdkProject = findProjectByName(root, sdkPackage, projects);
|
|
2261
2286
|
const sourceRoot = sdkProject ? sdkProject.sourceRoot || path.join(sdkProject.root, "src") : void 0;
|
|
@@ -2384,11 +2409,13 @@ function lookupSdkType(codegenFs, options, projects) {
|
|
|
2384
2409
|
mode: candidate.mode,
|
|
2385
2410
|
entryFile: path.relative(codegenFs.root, candidate.file),
|
|
2386
2411
|
triedEntries,
|
|
2387
|
-
declarations: decls.map((d) =>
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2412
|
+
declarations: decls.map((d) => {
|
|
2413
|
+
return {
|
|
2414
|
+
kind: d.getKindName(),
|
|
2415
|
+
file: path.relative(codegenFs.root, d.getSourceFile().getFilePath()),
|
|
2416
|
+
signature: signatureText(d)
|
|
2417
|
+
};
|
|
2418
|
+
})
|
|
2392
2419
|
};
|
|
2393
2420
|
}
|
|
2394
2421
|
return {
|
|
@@ -2851,7 +2878,11 @@ function validateOptions(codegenFs, options, projects) {
|
|
|
2851
2878
|
if (!options.appProject) {
|
|
2852
2879
|
throw new ValidationError("App project is required");
|
|
2853
2880
|
}
|
|
2854
|
-
const project = findProjectByName(
|
|
2881
|
+
const project = findProjectByName(
|
|
2882
|
+
codegenFs.root,
|
|
2883
|
+
options.appProject,
|
|
2884
|
+
projects
|
|
2885
|
+
);
|
|
2855
2886
|
if (!project) {
|
|
2856
2887
|
throw new ValidationError(
|
|
2857
2888
|
`Project "${options.appProject}" not found in workspace`
|