@alchemy.run/effect-cluster 0.0.0 → 2.0.0-beta.86

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.
Files changed (233) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +101 -4
  3. package/lib/AWS/Database.d.ts +54 -0
  4. package/lib/AWS/Database.d.ts.map +1 -0
  5. package/lib/AWS/Database.js +96 -0
  6. package/lib/AWS/Database.js.map +1 -0
  7. package/lib/AWS/EcsPool.d.ts +56 -0
  8. package/lib/AWS/EcsPool.d.ts.map +1 -0
  9. package/lib/AWS/EcsPool.js +87 -0
  10. package/lib/AWS/EcsPool.js.map +1 -0
  11. package/lib/AWS/index.d.ts +7 -0
  12. package/lib/AWS/index.d.ts.map +1 -0
  13. package/lib/AWS/index.js +7 -0
  14. package/lib/AWS/index.js.map +1 -0
  15. package/lib/AWS/internal/Gateway.d.ts +23 -0
  16. package/lib/AWS/internal/Gateway.d.ts.map +1 -0
  17. package/lib/AWS/internal/Gateway.js +70 -0
  18. package/lib/AWS/internal/Gateway.js.map +1 -0
  19. package/lib/Cloudflare/DurableObjectPool.d.ts +42 -0
  20. package/lib/Cloudflare/DurableObjectPool.d.ts.map +1 -0
  21. package/lib/Cloudflare/DurableObjectPool.js +136 -0
  22. package/lib/Cloudflare/DurableObjectPool.js.map +1 -0
  23. package/lib/Cloudflare/PoolWorker.d.ts +186 -0
  24. package/lib/Cloudflare/PoolWorker.d.ts.map +1 -0
  25. package/lib/Cloudflare/PoolWorker.js +75 -0
  26. package/lib/Cloudflare/PoolWorker.js.map +1 -0
  27. package/lib/Cloudflare/index.d.ts +7 -0
  28. package/lib/Cloudflare/index.d.ts.map +1 -0
  29. package/lib/Cloudflare/index.js +7 -0
  30. package/lib/Cloudflare/index.js.map +1 -0
  31. package/lib/Cloudflare/internal/Objects.d.ts +38 -0
  32. package/lib/Cloudflare/internal/Objects.d.ts.map +1 -0
  33. package/lib/Cloudflare/internal/Objects.js +102 -0
  34. package/lib/Cloudflare/internal/Objects.js.map +1 -0
  35. package/lib/Cron.d.ts +143 -0
  36. package/lib/Cron.d.ts.map +1 -0
  37. package/lib/Cron.js +83 -0
  38. package/lib/Cron.js.map +1 -0
  39. package/lib/Database.d.ts +95 -0
  40. package/lib/Database.d.ts.map +1 -0
  41. package/lib/Database.js +38 -0
  42. package/lib/Database.js.map +1 -0
  43. package/lib/Docker/Database.d.ts +42 -0
  44. package/lib/Docker/Database.d.ts.map +1 -0
  45. package/lib/Docker/Database.js +53 -0
  46. package/lib/Docker/Database.js.map +1 -0
  47. package/lib/Docker/SwarmPool.d.ts +44 -0
  48. package/lib/Docker/SwarmPool.d.ts.map +1 -0
  49. package/lib/Docker/SwarmPool.js +56 -0
  50. package/lib/Docker/SwarmPool.js.map +1 -0
  51. package/lib/Docker/index.d.ts +7 -0
  52. package/lib/Docker/index.d.ts.map +1 -0
  53. package/lib/Docker/index.js +7 -0
  54. package/lib/Docker/index.js.map +1 -0
  55. package/lib/Entity.d.ts +348 -0
  56. package/lib/Entity.d.ts.map +1 -0
  57. package/lib/Entity.js +308 -0
  58. package/lib/Entity.js.map +1 -0
  59. package/lib/Fly/Database.d.ts +50 -0
  60. package/lib/Fly/Database.d.ts.map +1 -0
  61. package/lib/Fly/Database.js +56 -0
  62. package/lib/Fly/Database.js.map +1 -0
  63. package/lib/Fly/MachinePool.d.ts +39 -0
  64. package/lib/Fly/MachinePool.d.ts.map +1 -0
  65. package/lib/Fly/MachinePool.js +51 -0
  66. package/lib/Fly/MachinePool.js.map +1 -0
  67. package/lib/Fly/index.d.ts +7 -0
  68. package/lib/Fly/index.d.ts.map +1 -0
  69. package/lib/Fly/index.js +7 -0
  70. package/lib/Fly/index.js.map +1 -0
  71. package/lib/GCP/ComputeEnginePool.d.ts +41 -0
  72. package/lib/GCP/ComputeEnginePool.d.ts.map +1 -0
  73. package/lib/GCP/ComputeEnginePool.js +172 -0
  74. package/lib/GCP/ComputeEnginePool.js.map +1 -0
  75. package/lib/GCP/Database.d.ts +48 -0
  76. package/lib/GCP/Database.d.ts.map +1 -0
  77. package/lib/GCP/Database.js +115 -0
  78. package/lib/GCP/Database.js.map +1 -0
  79. package/lib/GCP/index.d.ts +7 -0
  80. package/lib/GCP/index.d.ts.map +1 -0
  81. package/lib/GCP/index.js +7 -0
  82. package/lib/GCP/index.js.map +1 -0
  83. package/lib/Hetzner/Database.d.ts +48 -0
  84. package/lib/Hetzner/Database.d.ts.map +1 -0
  85. package/lib/Hetzner/Database.js +91 -0
  86. package/lib/Hetzner/Database.js.map +1 -0
  87. package/lib/Hetzner/ServerPool.d.ts +35 -0
  88. package/lib/Hetzner/ServerPool.d.ts.map +1 -0
  89. package/lib/Hetzner/ServerPool.js +98 -0
  90. package/lib/Hetzner/ServerPool.js.map +1 -0
  91. package/lib/Hetzner/index.d.ts +7 -0
  92. package/lib/Hetzner/index.d.ts.map +1 -0
  93. package/lib/Hetzner/index.js +7 -0
  94. package/lib/Hetzner/index.js.map +1 -0
  95. package/lib/Host.d.ts +60 -0
  96. package/lib/Host.d.ts.map +1 -0
  97. package/lib/Host.js +31 -0
  98. package/lib/Host.js.map +1 -0
  99. package/lib/Kubernetes/Database.d.ts +40 -0
  100. package/lib/Kubernetes/Database.d.ts.map +1 -0
  101. package/lib/Kubernetes/Database.js +56 -0
  102. package/lib/Kubernetes/Database.js.map +1 -0
  103. package/lib/Kubernetes/DeploymentPool.d.ts +54 -0
  104. package/lib/Kubernetes/DeploymentPool.d.ts.map +1 -0
  105. package/lib/Kubernetes/DeploymentPool.js +49 -0
  106. package/lib/Kubernetes/DeploymentPool.js.map +1 -0
  107. package/lib/Kubernetes/index.d.ts +7 -0
  108. package/lib/Kubernetes/index.d.ts.map +1 -0
  109. package/lib/Kubernetes/index.js +7 -0
  110. package/lib/Kubernetes/index.js.map +1 -0
  111. package/lib/Pool.d.ts +66 -0
  112. package/lib/Pool.d.ts.map +1 -0
  113. package/lib/Pool.js +47 -0
  114. package/lib/Pool.js.map +1 -0
  115. package/lib/Providers.d.ts +19 -0
  116. package/lib/Providers.d.ts.map +1 -0
  117. package/lib/Providers.js +31 -0
  118. package/lib/Providers.js.map +1 -0
  119. package/lib/ShardGroups.d.ts +24 -0
  120. package/lib/ShardGroups.d.ts.map +1 -0
  121. package/lib/ShardGroups.js +19 -0
  122. package/lib/ShardGroups.js.map +1 -0
  123. package/lib/Singleton.d.ts +110 -0
  124. package/lib/Singleton.d.ts.map +1 -0
  125. package/lib/Singleton.js +60 -0
  126. package/lib/Singleton.js.map +1 -0
  127. package/lib/Workflow.d.ts +251 -0
  128. package/lib/Workflow.d.ts.map +1 -0
  129. package/lib/Workflow.js +288 -0
  130. package/lib/Workflow.js.map +1 -0
  131. package/lib/index.d.ts +12 -0
  132. package/lib/index.d.ts.map +1 -0
  133. package/lib/index.js +12 -0
  134. package/lib/index.js.map +1 -0
  135. package/lib/internal/Bootstrap.d.ts +28 -0
  136. package/lib/internal/Bootstrap.d.ts.map +1 -0
  137. package/lib/internal/Bootstrap.js +257 -0
  138. package/lib/internal/Bootstrap.js.map +1 -0
  139. package/lib/internal/EntityRuntime.d.ts +40 -0
  140. package/lib/internal/EntityRuntime.d.ts.map +1 -0
  141. package/lib/internal/EntityRuntime.js +698 -0
  142. package/lib/internal/EntityRuntime.js.map +1 -0
  143. package/lib/internal/Gateway.d.ts +82 -0
  144. package/lib/internal/Gateway.d.ts.map +1 -0
  145. package/lib/internal/Gateway.js +218 -0
  146. package/lib/internal/Gateway.js.map +1 -0
  147. package/lib/internal/HostedPlatform.d.ts +36 -0
  148. package/lib/internal/HostedPlatform.d.ts.map +1 -0
  149. package/lib/internal/HostedPlatform.js +36 -0
  150. package/lib/internal/HostedPlatform.js.map +1 -0
  151. package/lib/internal/HostedRuntime.d.ts +58 -0
  152. package/lib/internal/HostedRuntime.d.ts.map +1 -0
  153. package/lib/internal/HostedRuntime.js +72 -0
  154. package/lib/internal/HostedRuntime.js.map +1 -0
  155. package/lib/internal/Naming.d.ts +12 -0
  156. package/lib/internal/Naming.d.ts.map +1 -0
  157. package/lib/internal/Naming.js +40 -0
  158. package/lib/internal/Naming.js.map +1 -0
  159. package/lib/internal/ObjectSharding.d.ts +141 -0
  160. package/lib/internal/ObjectSharding.d.ts.map +1 -0
  161. package/lib/internal/ObjectSharding.js +337 -0
  162. package/lib/internal/ObjectSharding.js.map +1 -0
  163. package/lib/internal/PoolHost.d.ts +80 -0
  164. package/lib/internal/PoolHost.d.ts.map +1 -0
  165. package/lib/internal/PoolHost.js +203 -0
  166. package/lib/internal/PoolHost.js.map +1 -0
  167. package/lib/internal/PoolHostService.d.ts +25 -0
  168. package/lib/internal/PoolHostService.d.ts.map +1 -0
  169. package/lib/internal/PoolHostService.js +10 -0
  170. package/lib/internal/PoolHostService.js.map +1 -0
  171. package/lib/internal/Wire.d.ts +60 -0
  172. package/lib/internal/Wire.d.ts.map +1 -0
  173. package/lib/internal/Wire.js +36 -0
  174. package/lib/internal/Wire.js.map +1 -0
  175. package/lib/internal/WorkflowGateway.d.ts +36 -0
  176. package/lib/internal/WorkflowGateway.d.ts.map +1 -0
  177. package/lib/internal/WorkflowGateway.js +124 -0
  178. package/lib/internal/WorkflowGateway.js.map +1 -0
  179. package/lib/internal/external-runner.d.ts +2 -0
  180. package/lib/internal/external-runner.d.ts.map +1 -0
  181. package/lib/internal/external-runner.js +7 -0
  182. package/lib/internal/external-runner.js.map +1 -0
  183. package/lib/internal/runner.d.ts +2 -0
  184. package/lib/internal/runner.d.ts.map +1 -0
  185. package/lib/internal/runner.js +5 -0
  186. package/lib/internal/runner.js.map +1 -0
  187. package/package.json +128 -3
  188. package/src/AWS/Database.ts +139 -0
  189. package/src/AWS/EcsPool.ts +118 -0
  190. package/src/AWS/index.ts +6 -0
  191. package/src/AWS/internal/Gateway.ts +82 -0
  192. package/src/Cloudflare/DurableObjectPool.ts +198 -0
  193. package/src/Cloudflare/PoolWorker.ts +124 -0
  194. package/src/Cloudflare/index.ts +6 -0
  195. package/src/Cloudflare/internal/Objects.ts +160 -0
  196. package/src/Cron.ts +202 -0
  197. package/src/Database.ts +116 -0
  198. package/src/Docker/Database.ts +94 -0
  199. package/src/Docker/SwarmPool.ts +83 -0
  200. package/src/Docker/index.ts +6 -0
  201. package/src/Entity.ts +621 -0
  202. package/src/Fly/Database.ts +102 -0
  203. package/src/Fly/MachinePool.ts +72 -0
  204. package/src/Fly/index.ts +6 -0
  205. package/src/GCP/ComputeEnginePool.ts +203 -0
  206. package/src/GCP/Database.ts +168 -0
  207. package/src/GCP/index.ts +6 -0
  208. package/src/Hetzner/Database.ts +142 -0
  209. package/src/Hetzner/ServerPool.ts +116 -0
  210. package/src/Hetzner/index.ts +6 -0
  211. package/src/Host.ts +68 -0
  212. package/src/Kubernetes/Database.ts +89 -0
  213. package/src/Kubernetes/DeploymentPool.ts +77 -0
  214. package/src/Kubernetes/index.ts +6 -0
  215. package/src/Pool.ts +104 -0
  216. package/src/Providers.ts +49 -0
  217. package/src/ShardGroups.ts +41 -0
  218. package/src/Singleton.ts +153 -0
  219. package/src/Workflow.ts +556 -0
  220. package/src/index.ts +11 -0
  221. package/src/internal/Bootstrap.ts +368 -0
  222. package/src/internal/EntityRuntime.ts +996 -0
  223. package/src/internal/Gateway.ts +366 -0
  224. package/src/internal/HostedPlatform.ts +83 -0
  225. package/src/internal/HostedRuntime.ts +118 -0
  226. package/src/internal/Naming.ts +44 -0
  227. package/src/internal/ObjectSharding.ts +578 -0
  228. package/src/internal/PoolHost.ts +330 -0
  229. package/src/internal/PoolHostService.ts +25 -0
  230. package/src/internal/Wire.ts +83 -0
  231. package/src/internal/WorkflowGateway.ts +188 -0
  232. package/src/internal/external-runner.ts +10 -0
  233. package/src/internal/runner.ts +5 -0
@@ -0,0 +1,31 @@
1
+ import * as Provider from "alchemy/Provider";
2
+ import { Random, RandomProvider } from "alchemy/Random";
3
+ import * as Layer from "effect/Layer";
4
+ import { CronProvider, CronResource } from "./Cron.js";
5
+ import { EntityProvider, EntityResource } from "./Entity.js";
6
+ import { Pool, PoolProvider } from "./Pool.js";
7
+ import { ShardGroups, ShardGroupsProvider } from "./ShardGroups.js";
8
+ import { SingletonProvider, SingletonResource } from "./Singleton.js";
9
+ import { WorkflowProvider, WorkflowResource } from "./Workflow.js";
10
+ /** Service tag bundling every Effect Cluster provider. */
11
+ export class Providers extends Provider.ProviderCollection()("Cluster") {
12
+ }
13
+ /**
14
+ * The Effect Cluster providers Layer. Add it next to the providers of the
15
+ * cloud your database and runners run on.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * Alchemy.Stack("App", { providers: Layer.mergeAll(Docker.providers(), Cluster.providers()) }, ...)
20
+ * ```
21
+ */
22
+ export const providers = () => Layer.effect(Providers, Provider.collection([
23
+ EntityResource,
24
+ WorkflowResource,
25
+ SingletonResource,
26
+ CronResource,
27
+ Pool,
28
+ ShardGroups,
29
+ Random,
30
+ ])).pipe(Layer.provide(Layer.mergeAll(EntityProvider(), WorkflowProvider(), SingletonProvider(), CronProvider(), PoolProvider(), ShardGroupsProvider(), RandomProvider())));
31
+ //# sourceMappingURL=Providers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Providers.js","sources":["../src/Providers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEnE,0DAA0D;AAC1D,MAAM,OAAO,SAAU,SAAQ,QAAQ,CAAC,kBAAkB,EAAa,CAAC,SAAS,CAAC;CAAG;AAIrF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,EAAE,CAC5B,KAAK,CAAC,MAAM,CACV,SAAS,EACT,QAAQ,CAAC,UAAU,CAAC;IAClB,cAAc;IACd,gBAAgB;IAChB,iBAAiB;IACjB,YAAY;IACZ,IAAI;IACJ,WAAW;IACX,MAAM;CACP,CAAC,CACH,CAAC,IAAI,CACJ,KAAK,CAAC,OAAO,CACX,KAAK,CAAC,QAAQ,CACZ,cAAc,EAAE,EAChB,gBAAgB,EAAE,EAClB,iBAAiB,EAAE,EACnB,YAAY,EAAE,EACd,YAAY,EAAE,EACd,mBAAmB,EAAE,EACrB,cAAc,EAAE,CACjB,CACF,CACF,CAAC"}
@@ -0,0 +1,24 @@
1
+ import * as Provider from "alchemy/Provider";
2
+ import { Resource } from "alchemy/Resource";
3
+ import type { Providers } from "./Providers.ts";
4
+ /** The shard groups one pool serves, bound onto its database's {@link ShardGroups}. */
5
+ export interface ShardGroupsBindingContract {
6
+ groups?: string[];
7
+ }
8
+ export interface ShardGroupsAttributes {
9
+ /** Every shard group in the cluster, sorted. */
10
+ groups: string[];
11
+ }
12
+ export interface ShardGroups extends Resource<"Cluster.ShardGroups", {}, ShardGroupsAttributes, ShardGroupsBindingContract, Providers> {
13
+ }
14
+ /**
15
+ * Every shard group in one cluster, collected from the pools that share
16
+ * its database. Every runner and gateway is configured with the whole list:
17
+ * Effect Cluster numbers each shard's lock by its group's place in it, so
18
+ * they must all agree. It owns nothing in the cloud.
19
+ *
20
+ * @internal
21
+ */
22
+ export declare const ShardGroups: import("alchemy").ResourceClass<ShardGroups>;
23
+ export declare const ShardGroupsProvider: () => import("effect/Layer").Layer<Provider.Provider<ShardGroups>, never, never>;
24
+ //# sourceMappingURL=ShardGroups.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ShardGroups.d.ts","sources":["../src/ShardGroups.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,uFAAuF;AACvF,MAAM,WAAW,0BAA0B;IACzC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,qBAAqB;IACpC,gDAAgD;IAChD,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,MAAM,WAAW,WAAY,SAAQ,QAAQ,CAC3C,qBAAqB,EACrB,EAAE,EACF,qBAAqB,EACrB,0BAA0B,EAC1B,SAAS,CACV;CAAG;AAEJ;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,8CAA+C,CAAC;AAExE,eAAO,MAAM,mBAAmB,kFAO5B,CAAC"}
@@ -0,0 +1,19 @@
1
+ import * as Provider from "alchemy/Provider";
2
+ import { Resource } from "alchemy/Resource";
3
+ import * as Effect from "effect/Effect";
4
+ /**
5
+ * Every shard group in one cluster, collected from the pools that share
6
+ * its database. Every runner and gateway is configured with the whole list:
7
+ * Effect Cluster numbers each shard's lock by its group's place in it, so
8
+ * they must all agree. It owns nothing in the cloud.
9
+ *
10
+ * @internal
11
+ */
12
+ export const ShardGroups = Resource("Cluster.ShardGroups");
13
+ export const ShardGroupsProvider = () => Provider.succeed(ShardGroups, {
14
+ reconcile: ({ bindings }) => Effect.sync(() => ({
15
+ groups: [...new Set(bindings.flatMap(({ data }) => data.groups ?? []))].sort(),
16
+ })),
17
+ delete: () => Effect.void,
18
+ });
19
+ //# sourceMappingURL=ShardGroups.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ShardGroups.js","sources":["../src/ShardGroups.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAqBxC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,QAAQ,CAAc,qBAAqB,CAAC,CAAC;AAExE,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,EAAE,CACtC,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE;IAC5B,SAAS,EAAE,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAC1B,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;QACjB,MAAM,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE;KAC/E,CAAC,CAAC;IACL,MAAM,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI;CAC1B,CAAC,CAAC"}
@@ -0,0 +1,110 @@
1
+ import type { InputProps } from "alchemy/Input";
2
+ import type { Named } from "alchemy/Named";
3
+ import type { PlatformIdentity, PlatformServices } from "alchemy/Platform";
4
+ import type { RuntimeContext } from "alchemy/RuntimeContext";
5
+ import type { Self } from "alchemy/Self";
6
+ import type * as ConfigError from "effect/Config";
7
+ import type * as Context from "effect/Context";
8
+ import type * as Effect from "effect/Effect";
9
+ import type * as Layer from "effect/Layer";
10
+ import type { Scope } from "effect/Scope";
11
+ import { type HostedProps, type HostedResource } from "./internal/HostedPlatform.ts";
12
+ import type { Providers } from "./Providers.ts";
13
+ export declare const SingletonTypeId = "Cluster.Singleton";
14
+ export type SingletonTypeId = typeof SingletonTypeId;
15
+ export type SingletonProps = HostedProps;
16
+ export interface ClusterSingleton extends HostedResource<SingletonTypeId> {
17
+ }
18
+ /**
19
+ * A singleton as a runner runs it: the fiber its Construction phase
20
+ * returned, and the services that phase ran with.
21
+ * @internal
22
+ */
23
+ export interface HostedSingleton {
24
+ readonly kind: "singleton";
25
+ readonly name: string;
26
+ readonly run: Effect.Effect<void, unknown, Scope>;
27
+ readonly context: Context.Context<never>;
28
+ }
29
+ type SingletonServices = ClusterSingleton | Providers | RuntimeContext | Self | Self<ClusterSingleton>;
30
+ /** The resource type behind every singleton, which the providers register. @internal */
31
+ export declare const SingletonResource: import("alchemy").Platform<HostedResource<"Cluster.Singleton", HostedProps>, any, unknown, import("./internal/HostedRuntime.ts").HostedRuntimeContext<HostedSingleton>, {}, HostedProps>;
32
+ export declare const SingletonProvider: () => Layer.Layer<import("alchemy").Provider<HostedResource<"Cluster.Singleton", HostedProps>>, never, never>;
33
+ /** A declared singleton, implemented by `.make(props, impl)`. */
34
+ export type SingletonTag<Self, Name extends string> = Named<Name> & PlatformIdentity<Name> & {
35
+ /**
36
+ * The singleton's implementation, as a Layer: an Effect that resolves
37
+ * bindings once per runner and returns the fiber to run. Provide a
38
+ * pool Layer to `impl` to deploy it; provide the returned Layer to
39
+ * the Stack.
40
+ */
41
+ make<InitReq = never>(props: InputProps<SingletonProps>, impl: Effect.Effect<Effect.Effect<void, unknown, Scope>, ConfigError.ConfigError, InitReq>): Layer.Layer<Self, never, Providers | Exclude<InitReq, SingletonServices | PlatformServices>>;
42
+ new (_: never): {};
43
+ };
44
+ /** A singleton declared with its implementation: the class is what deploys it. */
45
+ export type SingletonInline<Name extends string, Req> = Effect.Effect<ClusterSingleton, never, Req> & Named<Name> & PlatformIdentity<Name> & {
46
+ new (_: never): {};
47
+ };
48
+ /** The class surface of {@link Singleton}. */
49
+ export interface SingletonClass {
50
+ <Self>(): {
51
+ /**
52
+ * Declared with its implementation: an Effect that resolves bindings
53
+ * once per runner and returns the fiber. Provide a pool Layer to
54
+ * `impl` to deploy it; `yield*` the class in the Stack.
55
+ */
56
+ <const Name extends string, InitReq = never>(name: Name, props: InputProps<SingletonProps>, impl: Effect.Effect<Effect.Effect<void, unknown, Scope>, ConfigError.ConfigError, InitReq>): SingletonInline<Name, Providers | Exclude<InitReq, SingletonServices | PlatformServices>>;
57
+ /** A bare declaration, implemented by `.make(props, impl)`. */
58
+ <const Name extends string>(name: Name): SingletonTag<Self, Name>;
59
+ };
60
+ }
61
+ /**
62
+ * A **Singleton** on an Effect Cluster: one fiber, running on exactly one
63
+ * of its pool. If that runner stops, another starts it.
64
+ *
65
+ * Declare it by name, with its implementation: an Effect that resolves
66
+ * bindings once per runner and returns the fiber, which only the runner
67
+ * that owns the singleton runs. Providing a pool Layer to the
68
+ * implementation is what deploys it. Or declare it bare and implement it
69
+ * with `.make(props, impl)`, as a Layer.
70
+ *
71
+ * ### Declaring a singleton
72
+ * **Example:** A loop that runs once across the cluster
73
+ * ```typescript
74
+ * // src/Reaper.ts
75
+ * export default class Reaper extends Cluster.Singleton<Reaper>()(
76
+ * "Reaper",
77
+ * { main: import.meta.url },
78
+ * Effect.gen(function* () {
79
+ * const counters = yield* Counter;
80
+ * return Effect.gen(function* () {
81
+ * const counter = yield* counters.getByName("reaped");
82
+ * yield* counter.Increment({ amount: 1 });
83
+ * }).pipe(Effect.repeat(Schedule.spaced("1 minute")), Effect.orDie);
84
+ * }).pipe(Effect.provide(Default)),
85
+ * ) {}
86
+ * ```
87
+ *
88
+ * **Example:** Declared bare, and implemented as a Layer
89
+ * ```typescript
90
+ * // src/Reaper.ts
91
+ * export class Reaper extends Cluster.Singleton<Reaper>()("Reaper") {}
92
+ *
93
+ * // src/ReaperLive.ts
94
+ * export default Reaper.make(
95
+ * { main: import.meta.url },
96
+ * Effect.gen(function* () {
97
+ * const counters = yield* Counter;
98
+ * return Effect.gen(function* () {
99
+ * const counter = yield* counters.getByName("reaped");
100
+ * yield* counter.Increment({ amount: 1 });
101
+ * }).pipe(Effect.repeat(Schedule.spaced("1 minute")), Effect.orDie);
102
+ * }).pipe(Effect.provide(Default)),
103
+ * );
104
+ * ```
105
+ *
106
+ * @resource
107
+ */
108
+ export declare const Singleton: SingletonClass;
109
+ export {};
110
+ //# sourceMappingURL=Singleton.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Singleton.d.ts","sources":["../src/Singleton.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,KAAK,WAAW,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,cAAc,EAEpB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,eAAO,MAAM,eAAe,sBAAsB,CAAC;AACnD,MAAM,MAAM,eAAe,GAAG,OAAO,eAAe,CAAC;AAErD,MAAM,MAAM,cAAc,GAAG,WAAW,CAAC;AAEzC,MAAM,WAAW,gBAAiB,SAAQ,cAAc,CAAC,eAAe,CAAC;CAAG;AAE5E;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,IAA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QACR;;;;WAIG;QACH,CAAC,KAAK,CAAC,IAAI,SAAS,MAAM,EAAE,OAAO,GAAG,KAAK,EACzC,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,UAAU,CAAC,cAAc,CAAC,EACjC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,WAAW,CAAC,WAAW,EAAE,OAAO,CAAC,GACzF,eAAe,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,OAAO,EAAE,iBAAiB,GAAG,gBAAgB,CAAC,CAAC,CAAC;QAC7F,+DAA+D;QAC/D,CAAC,KAAK,CAAC,IAAI,SAAS,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;KACnE,CAAC;CACH;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,eAAO,MAAM,SAAS,EAAE,cAEwC,CAAC"}
@@ -0,0 +1,60 @@
1
+ import { makeHostedPlatform, } from "./internal/HostedPlatform.js";
2
+ export const SingletonTypeId = "Cluster.Singleton";
3
+ const { platform, provider, declare } = makeHostedPlatform(SingletonTypeId, (id, run, context) => ({
4
+ kind: "singleton",
5
+ name: id,
6
+ run: run,
7
+ context,
8
+ }));
9
+ /** The resource type behind every singleton, which the providers register. @internal */
10
+ export const SingletonResource = platform;
11
+ export const SingletonProvider = provider;
12
+ /**
13
+ * A **Singleton** on an Effect Cluster: one fiber, running on exactly one
14
+ * of its pool. If that runner stops, another starts it.
15
+ *
16
+ * Declare it by name, with its implementation: an Effect that resolves
17
+ * bindings once per runner and returns the fiber, which only the runner
18
+ * that owns the singleton runs. Providing a pool Layer to the
19
+ * implementation is what deploys it. Or declare it bare and implement it
20
+ * with `.make(props, impl)`, as a Layer.
21
+ *
22
+ * ### Declaring a singleton
23
+ * **Example:** A loop that runs once across the cluster
24
+ * ```typescript
25
+ * // src/Reaper.ts
26
+ * export default class Reaper extends Cluster.Singleton<Reaper>()(
27
+ * "Reaper",
28
+ * { main: import.meta.url },
29
+ * Effect.gen(function* () {
30
+ * const counters = yield* Counter;
31
+ * return Effect.gen(function* () {
32
+ * const counter = yield* counters.getByName("reaped");
33
+ * yield* counter.Increment({ amount: 1 });
34
+ * }).pipe(Effect.repeat(Schedule.spaced("1 minute")), Effect.orDie);
35
+ * }).pipe(Effect.provide(Default)),
36
+ * ) {}
37
+ * ```
38
+ *
39
+ * **Example:** Declared bare, and implemented as a Layer
40
+ * ```typescript
41
+ * // src/Reaper.ts
42
+ * export class Reaper extends Cluster.Singleton<Reaper>()("Reaper") {}
43
+ *
44
+ * // src/ReaperLive.ts
45
+ * export default Reaper.make(
46
+ * { main: import.meta.url },
47
+ * Effect.gen(function* () {
48
+ * const counters = yield* Counter;
49
+ * return Effect.gen(function* () {
50
+ * const counter = yield* counters.getByName("reaped");
51
+ * yield* counter.Increment({ amount: 1 });
52
+ * }).pipe(Effect.repeat(Schedule.spaced("1 minute")), Effect.orDie);
53
+ * }).pipe(Effect.provide(Default)),
54
+ * );
55
+ * ```
56
+ *
57
+ * @resource
58
+ */
59
+ export const Singleton = (() => (name, props, impl) => declare(name, {}, props, impl));
60
+ //# sourceMappingURL=Singleton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Singleton.js","sources":["../src/Singleton.ts"],"names":[],"mappings":"AAUA,OAAO,EAGL,kBAAkB,GACnB,MAAM,8BAA8B,CAAC;AAGtC,MAAM,CAAC,MAAM,eAAe,GAAG,mBAAmB,CAAC;AA0BnD,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,kBAAkB,CACxD,eAAe,EACf,CAAC,EAAE,EAAE,GAAG,EAAE,OAAO,EAAmB,EAAE,CAAC,CAAC;IACtC,IAAI,EAAE,WAAW;IACjB,IAAI,EAAE,EAAE;IACR,GAAG,EAAE,GAA6B;IAClC,OAAO;CACR,CAAC,CACH,CAAC;AAEF,wFAAwF;AACxF,MAAM,CAAC,MAAM,iBAAiB,GAAG,QAAQ,CAAC;AAC1C,MAAM,CAAC,MAAM,iBAAiB,GAAG,QAAQ,CAAC;AAgD1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,MAAM,CAAC,MAAM,SAAS,GAAmB,CAAC,GAAG,EAAE,CAC7C,CAAC,IAAY,EAAE,KAAkC,EAAE,IAAc,EAAE,EAAE,CACnE,OAAO,CAAC,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,CAA8B,CAAC"}
@@ -0,0 +1,251 @@
1
+ import type { InputProps } from "alchemy/Input";
2
+ import type { Named } from "alchemy/Named";
3
+ import { Platform, type PlatformIdentity, type PlatformProps, type PlatformServices } from "alchemy/Platform";
4
+ import * as Provider from "alchemy/Provider";
5
+ import type { Resource } from "alchemy/Resource";
6
+ import { RuntimeContext } from "alchemy/RuntimeContext";
7
+ import type { Self } from "alchemy/Self";
8
+ import { type Execute, type Implemented, type WorkflowClient } from "alchemy/Workflows";
9
+ import type * as ConfigError from "effect/Config";
10
+ import * as Context from "effect/Context";
11
+ import * as Effect from "effect/Effect";
12
+ import * as Layer from "effect/Layer";
13
+ import * as Redacted from "effect/Redacted";
14
+ import type * as Schema from "effect/Schema";
15
+ import { Workflow as EffectWorkflow, WorkflowEngine as EffectWorkflowEngine } from "effect/workflow";
16
+ import { type EntityBindingContract } from "./Entity.ts";
17
+ import { type HostedRuntimeContext } from "./internal/HostedRuntime.ts";
18
+ import type { Providers } from "./Providers.ts";
19
+ export declare const WorkflowTypeId = "Cluster.Workflow";
20
+ export type WorkflowTypeId = typeof WorkflowTypeId;
21
+ export interface WorkflowProps extends PlatformProps {
22
+ /**
23
+ * The module whose default export is this workflow: the class, or the
24
+ * Layer its `.make(...)` returned. Usually `import.meta.url`.
25
+ */
26
+ main: string;
27
+ }
28
+ export interface WorkflowAttributes {
29
+ /** The workflow's name. */
30
+ workflow: string;
31
+ /** The shard group of the pool that hosts it. */
32
+ pool: string | undefined;
33
+ /** The gateway URL callers start and read runs through. */
34
+ gateway: string | undefined;
35
+ /** The token callers present to the gateway. */
36
+ token: Redacted.Redacted<string> | undefined;
37
+ }
38
+ export interface ClusterWorkflow extends Resource<WorkflowTypeId, WorkflowProps, WorkflowAttributes, EntityBindingContract, Providers> {
39
+ }
40
+ /**
41
+ * A workflow as a runner runs it: the workflow, the handler its
42
+ * Construction phase returned, and the services that phase ran with.
43
+ * @internal
44
+ */
45
+ export interface HostedWorkflow {
46
+ readonly kind: "workflow";
47
+ readonly workflow: EffectWorkflow.Any;
48
+ readonly execute: (payload: any, executionId: string) => Effect.Effect<any, any, any>;
49
+ readonly context: Context.Context<never>;
50
+ }
51
+ export type WorkflowRuntimeContext = HostedRuntimeContext<HostedWorkflow>;
52
+ /** Services the Construction phase may use without the caller providing them. */
53
+ type WorkflowServices = ClusterWorkflow | Providers | RuntimeContext | Self | Self<ClusterWorkflow>;
54
+ /** The resource type behind every workflow, which the providers register. @internal */
55
+ export declare const WorkflowResource: Platform<ClusterWorkflow, WorkflowServices, unknown, WorkflowRuntimeContext, {}, WorkflowProps>;
56
+ type AnyWorkflow = EffectWorkflow.Workflow<string, any, any, any>;
57
+ type PayloadOf<W> = W extends EffectWorkflow.Workflow<any, infer P, any, any> ? P : never;
58
+ type SuccessOf<W> = W extends EffectWorkflow.Workflow<any, any, infer S, any> ? S : never;
59
+ type ErrorOf<W> = W extends EffectWorkflow.Workflow<any, any, any, infer E> ? E : never;
60
+ /** A workflow's handler, typed by its declaration. */
61
+ export type WorkflowHandler<W> = Execute<PayloadOf<W> & EffectWorkflow.AnyStructSchema, SuccessOf<W> & Schema.Top, ErrorOf<W> & Schema.Top, any>;
62
+ /**
63
+ * A declared workflow: the tag callers `yield*` for its client, carrying
64
+ * Effect's workflow surface (`.workflow`, `.execute`, `.withCompensation`),
65
+ * implemented by `.make(props, impl)`.
66
+ */
67
+ export type WorkflowTag<Self, W extends AnyWorkflow> = Effect.Effect<WorkflowClient<W>, never, Providers> & Named<W["_tag"]> & PlatformIdentity<W["_tag"]> & {
68
+ /** The Effect workflow behind the class, for Effect's own APIs. */
69
+ readonly workflow: W;
70
+ /** Run it as a child of the current workflow, as Effect's `Workflow.execute`. */
71
+ readonly execute: W["execute"];
72
+ /** Undo a step when the workflow fails later, as Effect's `withCompensation`. */
73
+ readonly withCompensation: W["withCompensation"];
74
+ /** Type the workflow's handler against its payload, success and error. */
75
+ of<Handler extends WorkflowHandler<W>>(handler: Handler): Handler;
76
+ /**
77
+ * The workflow's implementation, as a Layer: an Effect that resolves
78
+ * bindings once per runner and returns the handler. Provide a pool
79
+ * Layer to `impl` to deploy it; provide the returned Layer to the Stack.
80
+ */
81
+ make<InitReq = never>(props: InputProps<WorkflowProps>, impl: Effect.Effect<WorkflowHandler<W>, ConfigError.ConfigError, InitReq>): Layer.Layer<Self | Implemented<W["_tag"]>, never, Providers | Exclude<InitReq, WorkflowServices | PlatformServices>>;
82
+ new (_: never): WorkflowClient<W>;
83
+ };
84
+ /**
85
+ * A workflow declared with its implementation: the class callers `yield*`,
86
+ * which also deploys it.
87
+ */
88
+ export type WorkflowInline<W extends AnyWorkflow, Req> = Effect.Effect<WorkflowClient<W>, never, Req> & Named<W["_tag"]> & PlatformIdentity<W["_tag"]> & {
89
+ /** The Effect workflow behind the class, for Effect's own APIs. */
90
+ readonly workflow: W;
91
+ /** Run it as a child of the current workflow, as Effect's `Workflow.execute`. */
92
+ readonly execute: W["execute"];
93
+ /** Undo a step when the workflow fails later, as Effect's `withCompensation`. */
94
+ readonly withCompensation: W["withCompensation"];
95
+ /** Type the workflow's handler against its payload, success and error. */
96
+ of<Handler extends WorkflowHandler<W>>(handler: Handler): Handler;
97
+ new (_: never): WorkflowClient<W>;
98
+ };
99
+ type WorkflowOf<Name extends string, Payload extends Schema.Struct.Fields | EffectWorkflow.AnyStructSchema, Success extends Schema.Top, Error extends Schema.Top> = EffectWorkflow.Workflow<Name, Payload extends Schema.Struct.Fields ? Schema.Struct<Payload> : Payload, Success, Error>;
100
+ /** The class surface of {@link Workflow}. */
101
+ export interface WorkflowClass {
102
+ <Self>(): {
103
+ /**
104
+ * Declared like Effect's `Workflow.make`, with its implementation: an
105
+ * Effect that resolves bindings once per runner and returns the
106
+ * handler. Provide a pool Layer to `impl` to deploy it.
107
+ */
108
+ <const Name extends string, Payload extends Schema.Struct.Fields | EffectWorkflow.AnyStructSchema, Success extends Schema.Top = Schema.Void, Error extends Schema.Top = Schema.Never, InitReq = never>(name: Name, options: Parameters<typeof EffectWorkflow.make<Name, Payload, Success, Error>>[1], props: InputProps<WorkflowProps>, impl: Effect.Effect<WorkflowHandler<WorkflowOf<Name, Payload, Success, Error>>, ConfigError.ConfigError, InitReq>): WorkflowInline<WorkflowOf<Name, Payload, Success, Error>, Providers | Exclude<InitReq, WorkflowServices | PlatformServices>>;
109
+ /** Declared like Effect's `Workflow.make`, implemented by `.make(props, impl)`. */
110
+ <const Name extends string, Payload extends Schema.Struct.Fields | EffectWorkflow.AnyStructSchema, Success extends Schema.Top = Schema.Void, Error extends Schema.Top = Schema.Never>(name: Name, options: Parameters<typeof EffectWorkflow.make<Name, Payload, Success, Error>>[1]): WorkflowTag<Self, WorkflowOf<Name, Payload, Success, Error>>;
111
+ };
112
+ }
113
+ /**
114
+ * A durable **Workflow** on an Effect Cluster: each run is a workflow
115
+ * entity, so its activities are persisted, `DurableClock.sleep` is a
116
+ * delayed message, and a run continues on another runner if its runner
117
+ * dies.
118
+ *
119
+ * Declare it like Effect's `Workflow.make`, from a name and its schemas,
120
+ * with its implementation: an Effect that resolves bindings once per runner
121
+ * and returns the handler. Providing a pool Layer to the implementation is
122
+ * what deploys it. Or declare it bare and implement it with
123
+ * `.make(props, impl)`, as a Layer: callers import the bare declaration
124
+ * without bundling the implementation or its pool.
125
+ *
126
+ * `yield* PlaceOrder` from any runtime returns its client: `start` a run,
127
+ * then read, signal or interrupt it.
128
+ *
129
+ * ### Declaring a workflow
130
+ * **Example:** A workflow, with its implementation
131
+ * ```typescript
132
+ * // src/PlaceOrder.ts
133
+ * export default class PlaceOrder extends Cluster.Workflow<PlaceOrder>()(
134
+ * "PlaceOrder",
135
+ * {
136
+ * payload: { orderId: Schema.String },
137
+ * success: Schema.String,
138
+ * idempotencyKey: ({ orderId }) => orderId,
139
+ * },
140
+ * { main: import.meta.url },
141
+ * Effect.gen(function* () {
142
+ * const counters = yield* Counter;
143
+ * return Effect.fn(function* ({ orderId }) {
144
+ * const n = yield* Activity.make({
145
+ * name: "count",
146
+ * success: Schema.Int,
147
+ * execute: Effect.flatMap(counters.getByName("orders"), (counter) =>
148
+ * counter.Increment({ amount: 1 }),
149
+ * ),
150
+ * });
151
+ * return `order ${orderId} is #${n}`;
152
+ * });
153
+ * }).pipe(Effect.provide(Default)),
154
+ * ) {}
155
+ * ```
156
+ *
157
+ * ### Keeping its code out of its callers
158
+ * **Example:** A bare declaration, which callers import
159
+ * ```typescript
160
+ * // src/PlaceOrder.ts
161
+ * export class PlaceOrder extends Cluster.Workflow<PlaceOrder>()("PlaceOrder", {
162
+ * payload: { orderId: Schema.String },
163
+ * success: Schema.String,
164
+ * idempotencyKey: ({ orderId }) => orderId,
165
+ * }) {}
166
+ * ```
167
+ *
168
+ * **Example:** Its implementation, as a Layer, deployed to a pool
169
+ * ```typescript
170
+ * // src/PlaceOrderLive.ts
171
+ * export default PlaceOrder.make(
172
+ * { main: import.meta.url },
173
+ * Effect.gen(function* () {
174
+ * const counters = yield* Counter;
175
+ * return PlaceOrder.of(
176
+ * Effect.fn(function* ({ orderId }) {
177
+ * const n = yield* Activity.make({
178
+ * name: "count",
179
+ * success: Schema.Int,
180
+ * execute: Effect.flatMap(counters.getByName("orders"), (counter) =>
181
+ * counter.Increment({ amount: 1 }),
182
+ * ),
183
+ * });
184
+ * return `order ${orderId} is #${n}`;
185
+ * }),
186
+ * );
187
+ * }).pipe(Effect.provide(Default)),
188
+ * );
189
+ * ```
190
+ *
191
+ * ### Running a workflow
192
+ * **Example:** Start a run from any runtime
193
+ * ```typescript
194
+ * const placeOrder = yield* PlaceOrder;
195
+ * const run = yield* placeOrder.start({ orderId: "o-1" });
196
+ * const status = yield* run.status;
197
+ * ```
198
+ *
199
+ * **Example:** A child workflow, inside another workflow
200
+ * ```typescript
201
+ * const receipt = yield* PlaceOrder.execute({ orderId: "o-1" });
202
+ * ```
203
+ *
204
+ * @resource
205
+ */
206
+ export declare const Workflow: WorkflowClass;
207
+ declare const WorkflowEngineOutsideRuntime_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
208
+ readonly _tag: "Cluster.WorkflowEngineOutsideRuntime";
209
+ } & Readonly<A>;
210
+ /** A workflow started outside any runtime. */
211
+ export declare class WorkflowEngineOutsideRuntime extends WorkflowEngineOutsideRuntime_base<{
212
+ readonly message: string;
213
+ }> {
214
+ }
215
+ declare const WorkflowNotHosted_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
216
+ readonly _tag: "Cluster.WorkflowNotHosted";
217
+ } & Readonly<A>;
218
+ /** No `Cluster.Workflow` in the Stack hosts the workflow. */
219
+ export declare class WorkflowNotHosted extends WorkflowNotHosted_base<{
220
+ readonly workflow: string;
221
+ }> {
222
+ }
223
+ /**
224
+ * Run `Cluster.Workflow`s through Alchemy's engine-neutral
225
+ * `Workflows.RunWorkflow`: a `WorkflowEngine` that reaches each workflow
226
+ * through the gateway of the pool that hosts it. Use it for code that
227
+ * runs the same workflow on any engine; otherwise `yield*` the workflow.
228
+ *
229
+ * ### Running workflows on any engine
230
+ * **Example:** `Workflows.RunWorkflow` on the cluster
231
+ * ```typescript
232
+ * Effect.gen(function* () {
233
+ * const placeOrder = yield* Workflows.RunWorkflow(PlaceOrder.workflow);
234
+ * return {
235
+ * fetch: Effect.gen(function* () {
236
+ * const run = yield* placeOrder.start({ orderId: "o-1" });
237
+ * return yield* HttpServerResponse.json(yield* run.status);
238
+ * }),
239
+ * };
240
+ * }).pipe(Effect.provide(Cluster.WorkflowEngine(PlaceOrder)));
241
+ * ```
242
+ *
243
+ * @layer
244
+ * @provides WorkflowEngine
245
+ */
246
+ export declare const WorkflowEngine: <const Workflows extends ReadonlyArray<{
247
+ readonly workflow: EffectWorkflow.Any;
248
+ }>>(...runs: Workflows) => Layer.Layer<EffectWorkflowEngine.WorkflowEngine | Implemented<Workflows[number]["workflow"]["_tag"]>, never, Providers>;
249
+ export declare const WorkflowProvider: () => Layer.Layer<Provider.Provider<ClusterWorkflow>, never, never>;
250
+ export {};
251
+ //# sourceMappingURL=Workflow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Workflow.d.ts","sources":["../src/Workflow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EACL,QAAQ,EACR,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,QAAQ,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAe,MAAM,wBAAwB,CAAC;AACrE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,WAAW,EAGhB,KAAK,cAAc,EACpB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,KAAK,WAAW,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAE1C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