@kosdev-code/kos-codegen-core 0.1.0-next.783 → 0.1.0-next.789
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 +61 -4
- package/index.js.map +1 -1
- package/index.mjs +61 -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/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/package.json +2 -2
package/index.mjs
CHANGED
|
@@ -1766,10 +1766,11 @@ function addDecoratedProperty(cls, spec) {
|
|
|
1766
1766
|
cls.insertProperty(propertyInsertIndex(cls), {
|
|
1767
1767
|
name: spec.name,
|
|
1768
1768
|
type: spec.type,
|
|
1769
|
+
initializer: spec.initializer,
|
|
1769
1770
|
scope: spec.scope ? SCOPE_MAP[spec.scope] : void 0,
|
|
1770
|
-
hasExclamationToken: !!spec.hasExclamation,
|
|
1771
|
+
hasExclamationToken: spec.initializer ? false : !!spec.hasExclamation,
|
|
1771
1772
|
decorators: [
|
|
1772
|
-
{
|
|
1773
|
+
spec.bare && !spec.decoratorArgsText ? { name: spec.decoratorName } : {
|
|
1773
1774
|
name: spec.decoratorName,
|
|
1774
1775
|
arguments: spec.decoratorArgsText ? [spec.decoratorArgsText] : []
|
|
1775
1776
|
}
|
|
@@ -1872,7 +1873,7 @@ function addModelEffectToModel(codegenFs, options, projects) {
|
|
|
1872
1873
|
});
|
|
1873
1874
|
return { modelFilePath };
|
|
1874
1875
|
}
|
|
1875
|
-
const FRAMEWORK_TYPES = /* @__PURE__ */ new Set(["IKosDataModel", "IKosIdentifiable"]);
|
|
1876
|
+
const FRAMEWORK_TYPES$1 = /* @__PURE__ */ new Set(["IKosDataModel", "IKosIdentifiable"]);
|
|
1876
1877
|
function addDependencyToModel(codegenFs, options, projects) {
|
|
1877
1878
|
const logger = getCodegenLogger();
|
|
1878
1879
|
const { modelFilePath } = resolveModelFilePath(codegenFs, options, projects);
|
|
@@ -1894,7 +1895,7 @@ function addDependencyToModel(codegenFs, options, projects) {
|
|
|
1894
1895
|
)?.[1];
|
|
1895
1896
|
if (bean) named.push({ name: bean });
|
|
1896
1897
|
const depType = options.dependencyType?.trim();
|
|
1897
|
-
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)) {
|
|
1898
1899
|
named.push({ name: depType, isTypeOnly: true });
|
|
1899
1900
|
}
|
|
1900
1901
|
if (named.length) ensureNamedImport(sf, options.dependencyPackage, named);
|
|
@@ -1911,6 +1912,61 @@ function addDependencyToModel(codegenFs, options, projects) {
|
|
|
1911
1912
|
});
|
|
1912
1913
|
return { modelFilePath };
|
|
1913
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
|
+
}
|
|
1914
1970
|
function addTopicHandlerToModel(codegenFs, options, projects) {
|
|
1915
1971
|
const logger = getCodegenLogger();
|
|
1916
1972
|
const { modelFilePath } = resolveModelFilePath(codegenFs, options, projects);
|
|
@@ -3000,6 +3056,7 @@ export {
|
|
|
3000
3056
|
PluginHandlerFactory,
|
|
3001
3057
|
TrackingFileSystem,
|
|
3002
3058
|
ValidationError,
|
|
3059
|
+
addChildToModel,
|
|
3003
3060
|
addComputedToModel,
|
|
3004
3061
|
addConfigPropertyToModel,
|
|
3005
3062
|
addContainerSupportToModel,
|