diff --git a/packages/core/src/component.ts b/packages/core/src/component.ts index fd98c041..9380e4e4 100644 --- a/packages/core/src/component.ts +++ b/packages/core/src/component.ts @@ -27,10 +27,37 @@ export type RuntimeComponentSpec = Component & { parsedVersion: Version; }; -export function createComponent(options: Omit): RuntimeComponentSpec { - return { - ...options, - kind: 'Component', - parsedVersion: parseVersion(options.version), - }; +// partial some fields, use as param createComponent +export type ComponentDefinition = { + version: string; + metadata: Partial & { name: string }; + spec?: Partial; +}; + +export function createComponent(options: ComponentDefinition): RuntimeComponentSpec { + return ( + { + version: options.version, + kind: ('Component' as any), + parsedVersion: parseVersion(options.version), + metadata: { + description: '', + isDraggable: true, + isResizable: true, + displayName: options.metadata.name, + exampleProperties: {}, + exampleSize: [1, 1], + ...options.metadata, + }, + spec: { + properties: {}, + state: {}, + methods: [], + styleSlots: [], + slots: [], + events: [], + ...options.spec, + }, + } + ); } diff --git a/packages/core/src/module.ts b/packages/core/src/module.ts index 304b3bed..1f2b794f 100644 --- a/packages/core/src/module.ts +++ b/packages/core/src/module.ts @@ -23,10 +23,27 @@ export type RuntimeModuleSpec = Module & { parsedVersion: Version; }; -export function createModule(options: Omit): RuntimeModuleSpec { +// partial some fields, use as param createModule +export type ModuleDefinition = { + version: string; + metadata: Metadata; + spec?: Partial; +}; + +export function createModule(options: ModuleDefinition): RuntimeModuleSpec { return { - ...options, + version: options.version, kind: 'Module', parsedVersion: parseVersion(options.version), + metadata: { + name: options.metadata.name, + description: options.metadata.description, + }, + spec: { + properties: {}, + events: [], + stateMap: {}, + ...options.spec + }, }; } diff --git a/packages/core/src/trait.ts b/packages/core/src/trait.ts index 59a6a1a5..9a9e9328 100644 --- a/packages/core/src/trait.ts +++ b/packages/core/src/trait.ts @@ -23,10 +23,29 @@ export type RuntimeTraitSpec = Trait & { parsedVersion: Version; }; -export function createTrait(options: Omit): RuntimeTraitSpec { - return { - ...options, - kind: 'Trait', - parsedVersion: parseVersion(options.version), - }; +// partial some fields, use as param createTrait +export type TraitDefinition = { + version: string; + metadata: Metadata; + spec?: Partial; +}; + +export function createTrait(options: TraitDefinition): RuntimeTraitSpec { + return ( + { + version: options.version, + kind: ('Trait' as any), + parsedVersion: parseVersion(options.version), + metadata: { + name: options.metadata.name, + description: options.metadata.description, + }, + spec: { + properties: {}, + state: {}, + methods: [], + ...options.spec + }, + } + ); }