@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.js
CHANGED
|
@@ -668,7 +668,12 @@ function generateHook(codegenFs, templateDir, options, cwd, projects) {
|
|
|
668
668
|
generateFilesFromTemplates(
|
|
669
669
|
codegenFs,
|
|
670
670
|
templateDir,
|
|
671
|
-
path__namespace.join(
|
|
671
|
+
path__namespace.join(
|
|
672
|
+
projectRoot,
|
|
673
|
+
options.appDirectory,
|
|
674
|
+
"hooks",
|
|
675
|
+
normalized.nameDashCase
|
|
676
|
+
),
|
|
672
677
|
normalized
|
|
673
678
|
);
|
|
674
679
|
appendBarrelExport(
|
|
@@ -787,9 +792,7 @@ function generateContainerModel(codegenFs, templateDir, options, cwd, projects)
|
|
|
787
792
|
{ ...normalized, internal }
|
|
788
793
|
);
|
|
789
794
|
if (options.dataServices) {
|
|
790
|
-
logger.info(
|
|
791
|
-
`Generating data services for ${modelNameDashCase}`
|
|
792
|
-
);
|
|
795
|
+
logger.info(`Generating data services for ${modelNameDashCase}`);
|
|
793
796
|
generateFilesFromTemplates(
|
|
794
797
|
codegenFs,
|
|
795
798
|
path__namespace.join(templateDir, "services"),
|
|
@@ -895,9 +898,7 @@ function generateModel(params) {
|
|
|
895
898
|
const modelLocation = kosConfig?.generator?.defaults?.model?.folder || "";
|
|
896
899
|
const internal = !!kosConfig?.generator?.internal;
|
|
897
900
|
options.modelDirectory = options.modelDirectory || modelLocation;
|
|
898
|
-
logger.info(
|
|
899
|
-
`Generating model ${normalized.nameDashCase} in ${projectRoot}`
|
|
900
|
-
);
|
|
901
|
+
logger.info(`Generating model ${normalized.nameDashCase} in ${projectRoot}`);
|
|
901
902
|
generateFilesFromTemplates(
|
|
902
903
|
codegenFs,
|
|
903
904
|
path__namespace.join(modelTemplateDir, "model"),
|
|
@@ -1494,9 +1495,7 @@ class RegistrationFileTransformer {
|
|
|
1494
1495
|
const logger = getCodegenLogger();
|
|
1495
1496
|
const { registrationFilePath } = this.options;
|
|
1496
1497
|
if (!registrationFilePath || !this.codegenFs.exists(registrationFilePath)) {
|
|
1497
|
-
logger.warn(
|
|
1498
|
-
"Registration file not found, skipping registration updates"
|
|
1499
|
-
);
|
|
1498
|
+
logger.warn("Registration file not found, skipping registration updates");
|
|
1500
1499
|
return;
|
|
1501
1500
|
}
|
|
1502
1501
|
let content = this.codegenFs.read(registrationFilePath);
|
|
@@ -1688,9 +1687,7 @@ function ensureNamedImport(sourceFile, moduleSpecifier, names) {
|
|
|
1688
1687
|
}
|
|
1689
1688
|
}
|
|
1690
1689
|
function resolveSdkModuleSpecifier(sourceFile) {
|
|
1691
|
-
const decl = sourceFile.getImportDeclarations().find(
|
|
1692
|
-
(d) => d.getNamedImports().some((n) => n.getName() === "kosModel")
|
|
1693
|
-
);
|
|
1690
|
+
const decl = sourceFile.getImportDeclarations().find((d) => d.getNamedImports().some((n) => n.getName() === "kosModel"));
|
|
1694
1691
|
return decl?.getModuleSpecifierValue() ?? "@kosdev-code/kos-ui-sdk";
|
|
1695
1692
|
}
|
|
1696
1693
|
function getModelClass(sourceFile, preferName) {
|
|
@@ -1709,7 +1706,10 @@ function addClassDecorator(cls, name, opts) {
|
|
|
1709
1706
|
const decorators = cls.getDecorators();
|
|
1710
1707
|
const kosModelIdx = decorators.findIndex((d) => d.getName() === "kosModel");
|
|
1711
1708
|
const insertIdx = kosModelIdx >= 0 ? kosModelIdx + 1 : decorators.length;
|
|
1712
|
-
cls.insertDecorator(insertIdx, {
|
|
1709
|
+
cls.insertDecorator(insertIdx, {
|
|
1710
|
+
name: `${name}${typeArgs}`,
|
|
1711
|
+
arguments: args ? [args] : []
|
|
1712
|
+
});
|
|
1713
1713
|
}
|
|
1714
1714
|
function ensureDeclarationMerge(sourceFile, interfaceName, extendsExpr, typeParameters = []) {
|
|
1715
1715
|
const baseType = extendsExpr.split("<")[0].trim();
|
|
@@ -1741,7 +1741,9 @@ function addDecoratedMethod(cls, spec) {
|
|
|
1741
1741
|
name: spec.name,
|
|
1742
1742
|
isAsync: spec.isAsync,
|
|
1743
1743
|
returnType: spec.returnType,
|
|
1744
|
-
parameters: spec.parameters?.map((p) =>
|
|
1744
|
+
parameters: spec.parameters?.map((p) => {
|
|
1745
|
+
return { name: p.name, type: p.type };
|
|
1746
|
+
}),
|
|
1745
1747
|
statements: spec.statements,
|
|
1746
1748
|
decorators: [
|
|
1747
1749
|
{
|
|
@@ -1807,7 +1809,9 @@ function buildDecoratorArgs(options) {
|
|
|
1807
1809
|
top.push(`containerProperty: ${JSON.stringify(options.containerProperty)}`);
|
|
1808
1810
|
}
|
|
1809
1811
|
if (options.sortKey) {
|
|
1810
|
-
top.push(
|
|
1812
|
+
top.push(
|
|
1813
|
+
`containerOptions: { sortKey: ${JSON.stringify(options.sortKey)} }`
|
|
1814
|
+
);
|
|
1811
1815
|
}
|
|
1812
1816
|
return top.length ? `{ ${top.join(", ")} }` : "";
|
|
1813
1817
|
}
|
|
@@ -1864,7 +1868,9 @@ function addModelEffectToModel(codegenFs, options, projects) {
|
|
|
1864
1868
|
if (!codegenFs.exists(modelFilePath)) {
|
|
1865
1869
|
throw new Error(`Model file not found: ${modelFilePath}`);
|
|
1866
1870
|
}
|
|
1867
|
-
logger.info(
|
|
1871
|
+
logger.info(
|
|
1872
|
+
`Adding @kosModelEffect "${options.methodName}" to ${options.modelName}`
|
|
1873
|
+
);
|
|
1868
1874
|
transformSourceFile(codegenFs, modelFilePath, (sf) => {
|
|
1869
1875
|
const sdk = resolveSdkModuleSpecifier(sf);
|
|
1870
1876
|
ensureNamedImport(sf, sdk, [{ name: "kosModelEffect" }]);
|
|
@@ -1888,7 +1894,9 @@ function addDependencyToModel(codegenFs, options, projects) {
|
|
|
1888
1894
|
if (!codegenFs.exists(modelFilePath)) {
|
|
1889
1895
|
throw new Error(`Model file not found: ${modelFilePath}`);
|
|
1890
1896
|
}
|
|
1891
|
-
logger.info(
|
|
1897
|
+
logger.info(
|
|
1898
|
+
`Adding @kosDependency "${options.propertyName}" to ${options.modelName}`
|
|
1899
|
+
);
|
|
1892
1900
|
const argsParts = [`modelType: ${options.modelTypeRef}`];
|
|
1893
1901
|
if (options.id) argsParts.push(`id: ${JSON.stringify(options.id)}`);
|
|
1894
1902
|
transformSourceFile(codegenFs, modelFilePath, (sf) => {
|
|
@@ -1896,7 +1904,9 @@ function addDependencyToModel(codegenFs, options, projects) {
|
|
|
1896
1904
|
ensureNamedImport(sf, sdk, [{ name: "kosDependency" }]);
|
|
1897
1905
|
if (options.dependencyPackage) {
|
|
1898
1906
|
const named = [];
|
|
1899
|
-
const bean = options.modelTypeRef.match(
|
|
1907
|
+
const bean = options.modelTypeRef.match(
|
|
1908
|
+
/^([A-Za-z_$][\w$]*)\.type$/
|
|
1909
|
+
)?.[1];
|
|
1900
1910
|
if (bean) named.push({ name: bean });
|
|
1901
1911
|
const depType = options.dependencyType?.trim();
|
|
1902
1912
|
if (depType && /^[A-Za-z_$][\w$]*$/.test(depType) && !FRAMEWORK_TYPES.has(depType)) {
|
|
@@ -1922,7 +1932,9 @@ function addTopicHandlerToModel(codegenFs, options, projects) {
|
|
|
1922
1932
|
if (!codegenFs.exists(modelFilePath)) {
|
|
1923
1933
|
throw new Error(`Model file not found: ${modelFilePath}`);
|
|
1924
1934
|
}
|
|
1925
|
-
logger.info(
|
|
1935
|
+
logger.info(
|
|
1936
|
+
`Adding @kosTopicHandler "${options.handlerName}" to ${options.modelName}`
|
|
1937
|
+
);
|
|
1926
1938
|
const websocket = options.websocket ?? true;
|
|
1927
1939
|
const eventType = options.eventType || "unknown";
|
|
1928
1940
|
transformSourceFile(codegenFs, modelFilePath, (sf) => {
|
|
@@ -1948,7 +1960,9 @@ function addConfigPropertyToModel(codegenFs, options, projects) {
|
|
|
1948
1960
|
if (!codegenFs.exists(modelFilePath)) {
|
|
1949
1961
|
throw new Error(`Model file not found: ${modelFilePath}`);
|
|
1950
1962
|
}
|
|
1951
|
-
logger.info(
|
|
1963
|
+
logger.info(
|
|
1964
|
+
`Adding @kosConfigProperty "${options.propertyName}" to ${options.modelName}`
|
|
1965
|
+
);
|
|
1952
1966
|
const valueType = options.valueType || "unknown";
|
|
1953
1967
|
transformSourceFile(codegenFs, modelFilePath, (sf) => {
|
|
1954
1968
|
const sdk = resolveSdkModuleSpecifier(sf);
|
|
@@ -1989,7 +2003,9 @@ function addPropertyToModel(codegenFs, options, projects) {
|
|
|
1989
2003
|
}
|
|
1990
2004
|
const type = options.type || "string";
|
|
1991
2005
|
const initializer = options.initializer !== void 0 ? options.initializer : defaultInitializer(type);
|
|
1992
|
-
logger.info(
|
|
2006
|
+
logger.info(
|
|
2007
|
+
`Adding property "${options.propertyName}: ${type}" to ${options.modelName}`
|
|
2008
|
+
);
|
|
1993
2009
|
transformSourceFile(codegenFs, modelFilePath, (sf) => {
|
|
1994
2010
|
const cls = getModelClass(sf);
|
|
1995
2011
|
addPlainProperty(cls, {
|
|
@@ -2008,7 +2024,9 @@ function addComputedToModel(codegenFs, options, projects) {
|
|
|
2008
2024
|
if (!codegenFs.exists(modelFilePath)) {
|
|
2009
2025
|
throw new Error(`Model file not found: ${modelFilePath}`);
|
|
2010
2026
|
}
|
|
2011
|
-
logger.info(
|
|
2027
|
+
logger.info(
|
|
2028
|
+
`Adding computed getter "${options.name}" to ${options.modelName}`
|
|
2029
|
+
);
|
|
2012
2030
|
transformSourceFile(codegenFs, modelFilePath, (sf) => {
|
|
2013
2031
|
const cls = getModelClass(sf);
|
|
2014
2032
|
addGetter(cls, {
|
|
@@ -2069,7 +2087,9 @@ function addServiceRequestToModel(codegenFs, options, projects) {
|
|
|
2069
2087
|
`Adding @kosServiceRequest "${options.methodName}" (${method} ${options.servicePath}) to ${options.modelName}`
|
|
2070
2088
|
);
|
|
2071
2089
|
transformSourceFile(codegenFs, modelFilePath, (sf) => {
|
|
2072
|
-
ensureNamedImport(sf, serviceImport, [
|
|
2090
|
+
ensureNamedImport(sf, serviceImport, [
|
|
2091
|
+
{ name: "kosServiceRequest" }
|
|
2092
|
+
]);
|
|
2073
2093
|
ensureNamedImport(sf, resolveSdkModuleSpecifier(sf), [
|
|
2074
2094
|
{ name: "DependencyLifecycle" }
|
|
2075
2095
|
]);
|
|
@@ -2079,7 +2099,9 @@ function addServiceRequestToModel(codegenFs, options, projects) {
|
|
|
2079
2099
|
decoratorName: "kosServiceRequest",
|
|
2080
2100
|
decoratorArgsText: `{ path: ${JSON.stringify(
|
|
2081
2101
|
options.servicePath
|
|
2082
|
-
)}, method: ${JSON.stringify(
|
|
2102
|
+
)}, method: ${JSON.stringify(
|
|
2103
|
+
method
|
|
2104
|
+
)}, lifecycle: DependencyLifecycle.${lifecycle} }`,
|
|
2083
2105
|
returnType: "void",
|
|
2084
2106
|
statements: "// TODO: handle the typed response"
|
|
2085
2107
|
});
|
|
@@ -2101,7 +2123,9 @@ function validateModel(codegenFs, options, projects) {
|
|
|
2101
2123
|
throw new Error(`Model file not found: ${modelFilePath}`);
|
|
2102
2124
|
}
|
|
2103
2125
|
const project = new tsMorph.Project({ useInMemoryFileSystem: true });
|
|
2104
|
-
const sf = project.createSourceFile(modelFilePath, content, {
|
|
2126
|
+
const sf = project.createSourceFile(modelFilePath, content, {
|
|
2127
|
+
overwrite: true
|
|
2128
|
+
});
|
|
2105
2129
|
const findings = [];
|
|
2106
2130
|
const hasKosModel = sf.getClasses().some((c) => c.getDecorator("kosModel"));
|
|
2107
2131
|
if (!hasKosModel) {
|
|
@@ -2180,11 +2204,7 @@ function collectDecorated(cls, decoratorName) {
|
|
|
2180
2204
|
for (const m of cls.getMethods()) {
|
|
2181
2205
|
const dec = m.getDecorator(decoratorName);
|
|
2182
2206
|
if (dec) {
|
|
2183
|
-
visit(
|
|
2184
|
-
m.getName(),
|
|
2185
|
-
() => dec.getText(),
|
|
2186
|
-
m.getReturnTypeNode()?.getText()
|
|
2187
|
-
);
|
|
2207
|
+
visit(m.getName(), () => dec.getText(), m.getReturnTypeNode()?.getText());
|
|
2188
2208
|
}
|
|
2189
2209
|
}
|
|
2190
2210
|
for (const p of cls.getProperties()) {
|
|
@@ -2202,7 +2222,9 @@ function describeModel(codegenFs, options, projects) {
|
|
|
2202
2222
|
throw new Error(`Model file not found: ${modelFilePath}`);
|
|
2203
2223
|
}
|
|
2204
2224
|
const project = new tsMorph.Project({ useInMemoryFileSystem: true });
|
|
2205
|
-
const sf = project.createSourceFile(modelFilePath, content, {
|
|
2225
|
+
const sf = project.createSourceFile(modelFilePath, content, {
|
|
2226
|
+
overwrite: true
|
|
2227
|
+
});
|
|
2206
2228
|
let modelType;
|
|
2207
2229
|
const modelTypeDecl = sf.getVariableDeclaration("MODEL_TYPE");
|
|
2208
2230
|
if (modelTypeDecl) {
|
|
@@ -2277,7 +2299,10 @@ function resolveCandidateEntries(codegenFs, options, projects) {
|
|
|
2277
2299
|
const out = [];
|
|
2278
2300
|
if (options.entryFile) {
|
|
2279
2301
|
const abs = path__namespace.isAbsolute(options.entryFile) ? options.entryFile : path__namespace.join(root, options.entryFile);
|
|
2280
|
-
out.push({
|
|
2302
|
+
out.push({
|
|
2303
|
+
file: abs,
|
|
2304
|
+
mode: abs.endsWith(".d.ts") ? "declarations" : "source"
|
|
2305
|
+
});
|
|
2281
2306
|
}
|
|
2282
2307
|
const sdkProject = findProjectByName(root, sdkPackage, projects);
|
|
2283
2308
|
const sourceRoot = sdkProject ? sdkProject.sourceRoot || path__namespace.join(sdkProject.root, "src") : void 0;
|
|
@@ -2406,11 +2431,13 @@ function lookupSdkType(codegenFs, options, projects) {
|
|
|
2406
2431
|
mode: candidate.mode,
|
|
2407
2432
|
entryFile: path__namespace.relative(codegenFs.root, candidate.file),
|
|
2408
2433
|
triedEntries,
|
|
2409
|
-
declarations: decls.map((d) =>
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2434
|
+
declarations: decls.map((d) => {
|
|
2435
|
+
return {
|
|
2436
|
+
kind: d.getKindName(),
|
|
2437
|
+
file: path__namespace.relative(codegenFs.root, d.getSourceFile().getFilePath()),
|
|
2438
|
+
signature: signatureText(d)
|
|
2439
|
+
};
|
|
2440
|
+
})
|
|
2414
2441
|
};
|
|
2415
2442
|
}
|
|
2416
2443
|
return {
|
|
@@ -2873,7 +2900,11 @@ function validateOptions(codegenFs, options, projects) {
|
|
|
2873
2900
|
if (!options.appProject) {
|
|
2874
2901
|
throw new ValidationError("App project is required");
|
|
2875
2902
|
}
|
|
2876
|
-
const project = findProjectByName(
|
|
2903
|
+
const project = findProjectByName(
|
|
2904
|
+
codegenFs.root,
|
|
2905
|
+
options.appProject,
|
|
2906
|
+
projects
|
|
2907
|
+
);
|
|
2877
2908
|
if (!project) {
|
|
2878
2909
|
throw new ValidationError(
|
|
2879
2910
|
`Project "${options.appProject}" not found in workspace`
|