@spfn/core 0.2.0-beta.6 → 0.2.0-beta.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,6 +21,23 @@ import 'pg-boss';
21
21
  */
22
22
  declare function loadEnvFiles(): void;
23
23
 
24
+ /**
25
+ * Workflow router interface for @spfn/core integration
26
+ *
27
+ * This is a minimal interface that avoids circular dependency with @spfn/workflow.
28
+ * The actual WorkflowRouter from @spfn/workflow implements this interface.
29
+ */
30
+ interface WorkflowRouterLike {
31
+ /**
32
+ * Initialize the workflow engine
33
+ * Called by server during infrastructure initialization
34
+ *
35
+ * @internal
36
+ */
37
+ _init: (db: any, options?: {
38
+ largeOutputThreshold?: number;
39
+ }) => void;
40
+ }
24
41
  /**
25
42
  * CORS configuration options - inferred from hono/cors
26
43
  */
@@ -338,6 +355,39 @@ interface ServerConfig {
338
355
  */
339
356
  redis?: boolean;
340
357
  };
358
+ /**
359
+ * Workflow router for workflow orchestration
360
+ *
361
+ * Automatically initializes the workflow engine after database is ready.
362
+ * Workflows are defined using @spfn/workflow package.
363
+ *
364
+ * @example
365
+ * ```typescript
366
+ * import { defineWorkflowRouter } from '@spfn/workflow';
367
+ *
368
+ * const workflowRouter = defineWorkflowRouter([
369
+ * provisionTenant,
370
+ * deprovisionTenant,
371
+ * ]);
372
+ *
373
+ * export default defineServerConfig()
374
+ * .workflows(workflowRouter)
375
+ * .build();
376
+ * ```
377
+ */
378
+ workflows?: WorkflowRouterLike;
379
+ /**
380
+ * Workflow engine configuration
381
+ * Only used if workflows router is provided
382
+ */
383
+ workflowsConfig?: {
384
+ /**
385
+ * Large output threshold in bytes
386
+ * Outputs larger than this will be stored in external storage
387
+ * @default 1024 * 1024 (1MB)
388
+ */
389
+ largeOutputThreshold?: number;
390
+ };
341
391
  /**
342
392
  * Server lifecycle hooks for custom infrastructure setup and management
343
393
  * Allows initialization of custom services and resources at different stages
@@ -646,6 +696,27 @@ declare class ServerConfigBuilder {
646
696
  * Configure infrastructure initialization
647
697
  */
648
698
  infrastructure(infrastructure: ServerConfig['infrastructure']): this;
699
+ /**
700
+ * Register workflow router for workflow orchestration
701
+ *
702
+ * Automatically initializes the workflow engine after database is ready.
703
+ *
704
+ * @example
705
+ * ```typescript
706
+ * import { defineWorkflowRouter } from '@spfn/workflow';
707
+ *
708
+ * const workflowRouter = defineWorkflowRouter([
709
+ * provisionTenant,
710
+ * deprovisionTenant,
711
+ * ]);
712
+ *
713
+ * export default defineServerConfig()
714
+ * .routes(appRouter)
715
+ * .workflows(workflowRouter)
716
+ * .build();
717
+ * ```
718
+ */
719
+ workflows(router: ServerConfig['workflows'], config?: ServerConfig['workflowsConfig']): this;
649
720
  /**
650
721
  * Configure lifecycle hooks
651
722
  * Can be called multiple times - hooks will be executed in registration order
@@ -1073,6 +1073,20 @@ async function initializeInfrastructure(config2) {
1073
1073
  serverLogger.debug("Registering jobs...");
1074
1074
  await registerJobs(config2.jobs);
1075
1075
  }
1076
+ if (config2.workflows) {
1077
+ const infraConfig2 = getInfrastructureConfig(config2);
1078
+ if (!infraConfig2.database) {
1079
+ throw new Error(
1080
+ "Workflows require database connection. Ensure database is enabled in infrastructure config."
1081
+ );
1082
+ }
1083
+ serverLogger.debug("Initializing workflow engine...");
1084
+ config2.workflows._init(
1085
+ getDatabase(),
1086
+ config2.workflowsConfig
1087
+ );
1088
+ serverLogger.info("Workflow engine initialized");
1089
+ }
1076
1090
  }
1077
1091
  function startHttpServer(app, host, port) {
1078
1092
  serverLogger.debug(`Starting server on ${host}:${port}...`);
@@ -1517,6 +1531,33 @@ var ServerConfigBuilder = class {
1517
1531
  this.config.infrastructure = infrastructure;
1518
1532
  return this;
1519
1533
  }
1534
+ /**
1535
+ * Register workflow router for workflow orchestration
1536
+ *
1537
+ * Automatically initializes the workflow engine after database is ready.
1538
+ *
1539
+ * @example
1540
+ * ```typescript
1541
+ * import { defineWorkflowRouter } from '@spfn/workflow';
1542
+ *
1543
+ * const workflowRouter = defineWorkflowRouter([
1544
+ * provisionTenant,
1545
+ * deprovisionTenant,
1546
+ * ]);
1547
+ *
1548
+ * export default defineServerConfig()
1549
+ * .routes(appRouter)
1550
+ * .workflows(workflowRouter)
1551
+ * .build();
1552
+ * ```
1553
+ */
1554
+ workflows(router, config2) {
1555
+ this.config.workflows = router;
1556
+ if (config2) {
1557
+ this.config.workflowsConfig = config2;
1558
+ }
1559
+ return this;
1560
+ }
1520
1561
  /**
1521
1562
  * Configure lifecycle hooks
1522
1563
  * Can be called multiple times - hooks will be executed in registration order