@kosdev-code/kos-codegen-core 3.0.6 → 3.0.7
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.d.ts +2 -2
- package/index.d.ts.map +1 -1
- package/index.js +68 -4
- package/index.js.map +1 -1
- package/index.mjs +68 -4
- package/index.mjs.map +1 -1
- package/lib/generators/augment/ts-toolkit.d.ts +7 -0
- package/lib/generators/augment/ts-toolkit.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/index.d.ts +1 -1
- package/lib/generators/index.d.ts.map +1 -1
- package/lib/generators/member-mutators/add-child.d.ts +20 -0
- package/lib/generators/member-mutators/add-child.d.ts.map +1 -0
- package/lib/generators/member-mutators/index.d.ts +1 -0
- package/lib/generators/member-mutators/index.d.ts.map +1 -1
- package/lib/generators/update-model-index.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,
|
|
@@ -1759,10 +1766,11 @@ function addDecoratedProperty(cls, spec) {
|
|
|
1759
1766
|
cls.insertProperty(propertyInsertIndex(cls), {
|
|
1760
1767
|
name: spec.name,
|
|
1761
1768
|
type: spec.type,
|
|
1769
|
+
initializer: spec.initializer,
|
|
1762
1770
|
scope: spec.scope ? SCOPE_MAP[spec.scope] : void 0,
|
|
1763
|
-
hasExclamationToken: !!spec.hasExclamation,
|
|
1771
|
+
hasExclamationToken: spec.initializer ? false : !!spec.hasExclamation,
|
|
1764
1772
|
decorators: [
|
|
1765
|
-
{
|
|
1773
|
+
spec.bare && !spec.decoratorArgsText ? { name: spec.decoratorName } : {
|
|
1766
1774
|
name: spec.decoratorName,
|
|
1767
1775
|
arguments: spec.decoratorArgsText ? [spec.decoratorArgsText] : []
|
|
1768
1776
|
}
|
|
@@ -1865,7 +1873,7 @@ function addModelEffectToModel(codegenFs, options, projects) {
|
|
|
1865
1873
|
});
|
|
1866
1874
|
return { modelFilePath };
|
|
1867
1875
|
}
|
|
1868
|
-
const FRAMEWORK_TYPES = /* @__PURE__ */ new Set(["IKosDataModel", "IKosIdentifiable"]);
|
|
1876
|
+
const FRAMEWORK_TYPES$1 = /* @__PURE__ */ new Set(["IKosDataModel", "IKosIdentifiable"]);
|
|
1869
1877
|
function addDependencyToModel(codegenFs, options, projects) {
|
|
1870
1878
|
const logger = getCodegenLogger();
|
|
1871
1879
|
const { modelFilePath } = resolveModelFilePath(codegenFs, options, projects);
|
|
@@ -1887,7 +1895,7 @@ function addDependencyToModel(codegenFs, options, projects) {
|
|
|
1887
1895
|
)?.[1];
|
|
1888
1896
|
if (bean) named.push({ name: bean });
|
|
1889
1897
|
const depType = options.dependencyType?.trim();
|
|
1890
|
-
if (depType && /^[A-Za-z_$][\w$]*$/.test(depType) && !FRAMEWORK_TYPES.has(depType)) {
|
|
1898
|
+
if (depType && /^[A-Za-z_$][\w$]*$/.test(depType) && !FRAMEWORK_TYPES$1.has(depType)) {
|
|
1891
1899
|
named.push({ name: depType, isTypeOnly: true });
|
|
1892
1900
|
}
|
|
1893
1901
|
if (named.length) ensureNamedImport(sf, options.dependencyPackage, named);
|
|
@@ -1904,6 +1912,61 @@ function addDependencyToModel(codegenFs, options, projects) {
|
|
|
1904
1912
|
});
|
|
1905
1913
|
return { modelFilePath };
|
|
1906
1914
|
}
|
|
1915
|
+
const FRAMEWORK_TYPES = /* @__PURE__ */ new Set(["IKosDataModel", "IKosIdentifiable"]);
|
|
1916
|
+
function addChildToModel(codegenFs, options, projects) {
|
|
1917
|
+
const logger = getCodegenLogger();
|
|
1918
|
+
const shape = options.shape ?? "single";
|
|
1919
|
+
const { modelFilePath } = resolveModelFilePath(codegenFs, options, projects);
|
|
1920
|
+
if (!codegenFs.exists(modelFilePath)) {
|
|
1921
|
+
throw new Error(`Model file not found: ${modelFilePath}`);
|
|
1922
|
+
}
|
|
1923
|
+
logger.info(
|
|
1924
|
+
`Adding @kosChild "${options.propertyName}" (${shape}) to ${options.modelName}`
|
|
1925
|
+
);
|
|
1926
|
+
const childType = options.childType?.trim();
|
|
1927
|
+
transformSourceFile(codegenFs, modelFilePath, (sf) => {
|
|
1928
|
+
const sdk = resolveSdkModuleSpecifier(sf);
|
|
1929
|
+
const sdkImports = [
|
|
1930
|
+
{ name: "kosChild" }
|
|
1931
|
+
];
|
|
1932
|
+
if (shape === "container") sdkImports.push({ name: "KosModelContainer" });
|
|
1933
|
+
ensureNamedImport(sf, sdk, sdkImports);
|
|
1934
|
+
if (options.childPackage && childType && /^[A-Za-z_$][\w$]*$/.test(childType) && !FRAMEWORK_TYPES.has(childType)) {
|
|
1935
|
+
ensureNamedImport(sf, options.childPackage, [
|
|
1936
|
+
{ name: childType, isTypeOnly: true }
|
|
1937
|
+
]);
|
|
1938
|
+
}
|
|
1939
|
+
const cls = getModelClass(sf);
|
|
1940
|
+
if (shape === "container") {
|
|
1941
|
+
addDecoratedProperty(cls, {
|
|
1942
|
+
name: options.propertyName,
|
|
1943
|
+
decoratorName: "kosChild",
|
|
1944
|
+
bare: true,
|
|
1945
|
+
initializer: `new KosModelContainer<${childType}>()`,
|
|
1946
|
+
scope: "private"
|
|
1947
|
+
});
|
|
1948
|
+
} else if (shape === "array") {
|
|
1949
|
+
addDecoratedProperty(cls, {
|
|
1950
|
+
name: options.propertyName,
|
|
1951
|
+
decoratorName: "kosChild",
|
|
1952
|
+
bare: true,
|
|
1953
|
+
type: `${childType}[]`,
|
|
1954
|
+
initializer: "[]",
|
|
1955
|
+
scope: "private"
|
|
1956
|
+
});
|
|
1957
|
+
} else {
|
|
1958
|
+
addDecoratedProperty(cls, {
|
|
1959
|
+
name: options.propertyName,
|
|
1960
|
+
decoratorName: "kosChild",
|
|
1961
|
+
bare: true,
|
|
1962
|
+
type: childType,
|
|
1963
|
+
scope: "private",
|
|
1964
|
+
hasExclamation: true
|
|
1965
|
+
});
|
|
1966
|
+
}
|
|
1967
|
+
});
|
|
1968
|
+
return { modelFilePath };
|
|
1969
|
+
}
|
|
1907
1970
|
function addTopicHandlerToModel(codegenFs, options, projects) {
|
|
1908
1971
|
const logger = getCodegenLogger();
|
|
1909
1972
|
const { modelFilePath } = resolveModelFilePath(codegenFs, options, projects);
|
|
@@ -2993,6 +3056,7 @@ export {
|
|
|
2993
3056
|
PluginHandlerFactory,
|
|
2994
3057
|
TrackingFileSystem,
|
|
2995
3058
|
ValidationError,
|
|
3059
|
+
addChildToModel,
|
|
2996
3060
|
addComputedToModel,
|
|
2997
3061
|
addConfigPropertyToModel,
|
|
2998
3062
|
addContainerSupportToModel,
|