File tree 1 file changed +42
-0
lines changed
packages/host/app/commands
1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { service } from '@ember/service' ;
2
+
3
+ import { type LooseSingleCardDocument } from '@cardstack/runtime-common' ;
4
+
5
+ import type * as BaseCommandModule from 'https://cardstack.com/base/command' ;
6
+
7
+ import HostBaseCommand from '../lib/host-base-command' ;
8
+
9
+ import CardService from '../services/card-service' ;
10
+
11
+ export default class CreateCardInstanceCommand extends HostBaseCommand <
12
+ typeof BaseCommandModule . CreateInstanceInput
13
+ > {
14
+ @service declare private cardService : CardService ;
15
+
16
+ description = `Create a new card instance given a card ref and realm.` ;
17
+
18
+ async getInputType ( ) {
19
+ let commandModule = await this . loadCommandModule ( ) ;
20
+ const { CreateInstanceInput } = commandModule ;
21
+ return CreateInstanceInput ;
22
+ }
23
+
24
+ protected async run (
25
+ input : BaseCommandModule . CreateInstanceInput ,
26
+ ) : Promise < undefined > {
27
+ if ( ! input . module || ! input . realm ) {
28
+ throw new Error (
29
+ "Create instance command can't run because it doesn't have all the fields in arguments returned by open ai" ,
30
+ ) ;
31
+ }
32
+ let doc : LooseSingleCardDocument = {
33
+ data : {
34
+ meta : {
35
+ adoptsFrom : input . module ,
36
+ realmURL : input . realm ,
37
+ } ,
38
+ } ,
39
+ } ;
40
+ await this . cardService . createFromSerialized ( doc . data , doc ) ;
41
+ }
42
+ }
You can’t perform that action at this time.
0 commit comments