11import { CloudAPIGroup } from "@inspatial/cloud" ;
2+ import { raiseORMException } from "../../orm/mod.ts" ;
23
34export const devActions = new CloudAPIGroup ( "dev" , {
45 description : "Development actions" ,
@@ -13,7 +14,46 @@ devActions.addAction("generateConfig", {
1314 inCloud . generateConfigFile ( ) ;
1415 } ,
1516} ) ;
17+ devActions . addAction ( "run" , {
18+ params : [ {
19+ key : "code" ,
20+ type : "TextField" ,
21+ } ] ,
1622
23+ async run ( { inCloud, orm, params : { code } } ) {
24+ if ( inCloud . getExtensionConfigValue ( "core" , "cloudMode" ) === "production" ) {
25+ raiseORMException (
26+ "The run action is not available in production mode" ,
27+ "Dev" ,
28+ 403 ,
29+ ) ;
30+ }
31+ const resultRows : Array < any > = [ ] ;
32+ const log = ( ...args : any [ ] ) => {
33+ for ( const arg of args ) {
34+ resultRows . push ( arg ) ;
35+ }
36+ } ;
37+ const func = new Function (
38+ "inCloud" ,
39+ "orm" ,
40+ "log" ,
41+ `return (async () => { ${ code } })()` ,
42+ ) ;
43+ try {
44+ const result = await func ( inCloud , orm , log ) ;
45+ return {
46+ result,
47+ log : resultRows ,
48+ } ;
49+ } catch ( error ) {
50+ return {
51+ result : { error : ( error as Error ) . message } ,
52+ log : resultRows ,
53+ } ;
54+ }
55+ } ,
56+ } ) ;
1757devActions . addAction ( "clearStaticCache" , {
1858 description : "Clear the static files cache" ,
1959 params : [ ] ,
0 commit comments