Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/breezy-games-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@plutolang/static-generator": patch
"@plutolang/base": patch
---

fix(generator): failed to generate iac code due to missing type information in webpack
12 changes: 7 additions & 5 deletions components/generators/static/src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,20 @@ export class StaticGenerator extends core.Generator {
const globalImports = `import { createClosure } from "@plutolang/base/closure";`;
let infraCode = ``;
for (const entity of entities) {
if (entity instanceof arch.Resource) {
if (arch.isResource(entity)) {
infraCode += this.generateInfraCode_Resource(entity);
} else if (entity instanceof arch.Closure) {
} else if (arch.isClosure(entity)) {
infraCode += this.generateInfraCode_Closure(entity, archRef);
} else if (entity instanceof arch.Relationship) {
} else if (arch.isRelationship(entity)) {
infraCode += this.generateInfraCode_Relationship(entity);
} else {
throw new Error(`Unsupported entity type ` + JSON.stringify(entity));
}
}

// Append the postProcess calling for each resource.
entities
.filter((entity) => entity instanceof arch.Resource)
.filter((entity) => arch.isResource(entity))
.forEach((entity) => {
const resource = entity as arch.Resource;
infraCode += `${resource.id}.postProcess();\n`;
Expand All @@ -53,7 +55,7 @@ export class StaticGenerator extends core.Generator {
// necessity, as this approach requires the SDK developer to specifically write outputs for
// certain resources, which may not be developer-friendly.
const outputItems = entities
.filter((entity) => entity instanceof arch.Resource)
.filter((entity) => arch.isResource(entity))
.map((entity) => {
const resource = entity as arch.Resource;
return `${resource.id}: ${resource.id}.outputs`;
Expand Down
12 changes: 12 additions & 0 deletions packages/base/arch/closure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,15 @@ export class Closure {
public readonly path: string
) {}
}

export function isClosure(obj: any): obj is Closure {
const fakeClosure = new Closure("", "");
const props = Object.getOwnPropertyNames(fakeClosure);
for (const prop of props) {
if (!(prop in obj) || typeof (fakeClosure as any)[prop] !== typeof obj[prop]) {
// If the property is not in the object or the type is different, return false.
return false;
}
}
return true;
}
6 changes: 3 additions & 3 deletions packages/base/arch/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export { Architecture, parseArchFromYaml } from "./architecture";
export { Parameter } from "./parameter";
export { Resource } from "./resource";
export { Closure } from "./closure";
export { Relationship, RelatType, IdWithType } from "./relationship";
export { Resource, isResource } from "./resource";
export { Closure, isClosure } from "./closure";
export { Relationship, isRelationship, RelatType, IdWithType } from "./relationship";
export * from "./types";
19 changes: 19 additions & 0 deletions packages/base/arch/relationship.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,22 @@ export class Relationship {
return this.parameters.map((item) => item.value).join(", ");
}
}

export function isRelationship(obj: any): obj is Relationship {
const fakeIdWithType: IdWithType = { id: "", type: "resource" };
const fakeRelationship = new Relationship(
fakeIdWithType,
[fakeIdWithType],
RelatType.Create,
"",
[]
);
const props = Object.getOwnPropertyNames(fakeRelationship);
for (const prop of props) {
if (!(prop in obj) || typeof (fakeRelationship as any)[prop] !== typeof obj[prop]) {
// If the property is not in the object or the type is different, return false.
return false;
}
}
return true;
}
12 changes: 12 additions & 0 deletions packages/base/arch/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,15 @@ export class Resource {
return this.parameters.map((item) => item.value).join(", ");
}
}

export function isResource(obj: any): obj is Resource {
const fakeResource = new Resource("", "", "", []);
const props = Object.getOwnPropertyNames(fakeResource);
for (const prop of props) {
if (!(prop in obj) || typeof (fakeResource as any)[prop] !== typeof obj[prop]) {
// If the property is not in the object or the type is different, return false.
return false;
}
}
return true;
}