Skip to main content
Glama
2-create_and_upgrade_component.ts3.46 kB
import assert from "node:assert"; import { SdfApiClient } from "../sdf_api_client.ts"; import { createComponent, createComponentPayload, eventualMVAssert, getViews, runWithTemporaryChangeset, } from "../test_helpers.ts"; export default async function create_and_upgrade_component( sdfApiClient: SdfApiClient, changeSetId: string, ) { if (changeSetId) { return await create_and_upgrade_component_inner(sdfApiClient, changeSetId); } else { return runWithTemporaryChangeset( sdfApiClient, create_and_upgrade_component_inner, ); } } async function create_and_upgrade_component_inner( sdfApiClient: SdfApiClient, changeSetId: string, ) { let createComponentBody = await createComponentPayload( sdfApiClient, changeSetId, "Region", ); // Get the views and find the default one const views = await getViews(sdfApiClient, changeSetId); const defaultView = views.find((v: any) => v.isDefault); assert(defaultView, "Expected to find a default view"); // Create a region component const newComponentId = await createComponent( sdfApiClient, changeSetId, defaultView.id, createComponentBody, ); assert(newComponentId, "Expected to get a component id after creation"); const region = await sdfApiClient.changeSetMjolnir( changeSetId, "Component", newComponentId, ); assert(region, "Expected to get a region after creation"); const originalSchemaVariantId = region.schemaVariantId.id; assert( originalSchemaVariantId, "Expected to get a schema variant id after creation", ); const schemaId = region.schemaId; assert(schemaId, "Expected to get a schema id after creation"); // ensure this schema is the default variant and there is no editing variant const schemaMembers = await sdfApiClient.changeSetMjolnir( changeSetId, "SchemaMembers", schemaId, ); assert(schemaMembers, "Expected to get a schema after creation"); assert( schemaMembers.defaultVariantId === originalSchemaVariantId, "Expected default variant to match original schema variant id", ); assert( schemaMembers.editingVariantId === null, "Expected no editing variant for the schema", ); // unlock the region schema variant const newSchemaVariant = await sdfApiClient.call({ route: "create_unlocked_copy", routeVars: { workspaceId: sdfApiClient.workspaceId, changeSetId, schemaVariantId: originalSchemaVariantId, }, }); assert( newSchemaVariant, "Expected to get a new schema variant after unlocking", ); console.log("Created new schema variant:", newSchemaVariant); // see that the component has an upgrade available await eventualMVAssert( sdfApiClient, changeSetId, "SchemaMembers", schemaId, (mv) => mv.defaultVariantId === originalSchemaVariantId && mv.editingVariantId !== null, "Component MV should have upgradeAvailable set to true", ); // upgrade the component const upgradeResp = await sdfApiClient.call({ route: "upgrade", routeVars: { workspaceId: sdfApiClient.workspaceId, changeSetId, }, body: { componentIds: [newComponentId], }, }); // see that the upgrade succeeds await eventualMVAssert( sdfApiClient, changeSetId, "Component", newComponentId, (mv) => mv.schemaVariantId !== originalSchemaVariantId, "Component MV should have been upgraded", ); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/systeminit/si'

If you have feedback or need assistance with the MCP directory API, please join our Discord server