alchemy 2.0.0-beta.1 → 2.0.0-beta.2

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 (129) hide show
  1. package/bin/alchemy-effect.js +31 -16
  2. package/bin/alchemy-effect.js.map +1 -1
  3. package/bin/alchemy-effect.sh +2 -3
  4. package/bin/alchemy-effect.ts +3 -3
  5. package/lib/cli/index.d.ts +39 -36
  6. package/lib/cli/index.d.ts.map +1 -1
  7. package/package.json +1 -1
  8. package/src/AWS/ACM/Certificate.ts +49 -46
  9. package/src/AWS/AutoScaling/AutoScalingGroup.ts +4 -1
  10. package/src/AWS/AutoScaling/LaunchTemplate.ts +3 -1
  11. package/src/AWS/AutoScaling/ScalingPolicy.ts +4 -1
  12. package/src/AWS/CloudFront/Distribution.ts +4 -1
  13. package/src/AWS/CloudFront/Function.ts +4 -1
  14. package/src/AWS/CloudFront/Invalidation.ts +4 -1
  15. package/src/AWS/CloudFront/KeyValueStore.ts +4 -1
  16. package/src/AWS/CloudFront/KvEntries.ts +4 -1
  17. package/src/AWS/CloudFront/KvRoutesUpdate.ts +4 -1
  18. package/src/AWS/CloudFront/OriginAccessControl.ts +4 -1
  19. package/src/AWS/CloudWatch/Alarm.ts +4 -1
  20. package/src/AWS/CloudWatch/AlarmMuteRule.ts +4 -1
  21. package/src/AWS/CloudWatch/AnomalyDetector.ts +4 -1
  22. package/src/AWS/CloudWatch/CompositeAlarm.ts +4 -1
  23. package/src/AWS/CloudWatch/Dashboard.ts +4 -1
  24. package/src/AWS/CloudWatch/InsightRule.ts +4 -1
  25. package/src/AWS/CloudWatch/MetricStream.ts +4 -1
  26. package/src/AWS/DynamoDB/Table.ts +3 -1
  27. package/src/AWS/EC2/EIP.ts +4 -1
  28. package/src/AWS/EC2/EgressOnlyInternetGateway.ts +4 -1
  29. package/src/AWS/EC2/Instance.ts +3 -1
  30. package/src/AWS/EC2/InternetGateway.ts +4 -1
  31. package/src/AWS/EC2/NatGateway.ts +4 -1
  32. package/src/AWS/EC2/NetworkAcl.ts +4 -1
  33. package/src/AWS/EC2/NetworkAclAssociation.ts +4 -1
  34. package/src/AWS/EC2/NetworkAclEntry.ts +4 -1
  35. package/src/AWS/EC2/Route.ts +4 -1
  36. package/src/AWS/EC2/RouteTable.ts +4 -1
  37. package/src/AWS/EC2/RouteTableAssociation.ts +4 -1
  38. package/src/AWS/EC2/SecurityGroup.ts +4 -1
  39. package/src/AWS/EC2/SecurityGroupRule.ts +4 -1
  40. package/src/AWS/EC2/Subnet.ts +4 -1
  41. package/src/AWS/EC2/Vpc.ts +4 -1
  42. package/src/AWS/EC2/VpcEndpoint.ts +4 -1
  43. package/src/AWS/ECR/Repository.ts +4 -1
  44. package/src/AWS/ECS/Cluster.ts +4 -1
  45. package/src/AWS/ECS/Service.ts +4 -1
  46. package/src/AWS/ECS/Task.ts +3 -1
  47. package/src/AWS/EKS/AccessEntry.ts +4 -1
  48. package/src/AWS/EKS/Addon.ts +4 -1
  49. package/src/AWS/EKS/Cluster.ts +3 -1
  50. package/src/AWS/EKS/PodIdentityAssociation.ts +4 -1
  51. package/src/AWS/ELBv2/Listener.ts +4 -1
  52. package/src/AWS/ELBv2/LoadBalancer.ts +4 -1
  53. package/src/AWS/ELBv2/TargetGroup.ts +4 -1
  54. package/src/AWS/EventBridge/EventBus.ts +4 -1
  55. package/src/AWS/EventBridge/Permission.ts +4 -1
  56. package/src/AWS/EventBridge/Rule.ts +4 -1
  57. package/src/AWS/IAM/AccessKey.ts +4 -1
  58. package/src/AWS/IAM/AccountAlias.ts +4 -1
  59. package/src/AWS/IAM/AccountPasswordPolicy.ts +4 -1
  60. package/src/AWS/IAM/Group.ts +4 -1
  61. package/src/AWS/IAM/GroupMembership.ts +4 -1
  62. package/src/AWS/IAM/InstanceProfile.ts +4 -1
  63. package/src/AWS/IAM/LoginProfile.ts +4 -1
  64. package/src/AWS/IAM/OpenIDConnectProvider.ts +4 -1
  65. package/src/AWS/IAM/Policy.ts +4 -1
  66. package/src/AWS/IAM/Role.ts +4 -1
  67. package/src/AWS/IAM/SAMLProvider.ts +4 -1
  68. package/src/AWS/IAM/SSHPublicKey.ts +4 -1
  69. package/src/AWS/IAM/ServerCertificate.ts +4 -1
  70. package/src/AWS/IAM/ServiceSpecificCredential.ts +4 -1
  71. package/src/AWS/IAM/SigningCertificate.ts +4 -1
  72. package/src/AWS/IAM/User.ts +4 -1
  73. package/src/AWS/IAM/VirtualMFADevice.ts +4 -1
  74. package/src/AWS/IdentityCenter/AccountAssignment.ts +4 -1
  75. package/src/AWS/IdentityCenter/Group.ts +4 -1
  76. package/src/AWS/IdentityCenter/Instance.ts +4 -1
  77. package/src/AWS/IdentityCenter/PermissionSet.ts +4 -1
  78. package/src/AWS/Kinesis/Stream.ts +4 -1
  79. package/src/AWS/Kinesis/StreamConsumer.ts +4 -1
  80. package/src/AWS/Lambda/EventSourceMapping.ts +4 -1
  81. package/src/AWS/Lambda/Function.ts +3 -1
  82. package/src/AWS/Lambda/Permission.ts +4 -1
  83. package/src/AWS/Logs/LogGroup.ts +4 -1
  84. package/src/AWS/Organizations/Account.ts +4 -1
  85. package/src/AWS/Organizations/DelegatedAdministrator.ts +4 -1
  86. package/src/AWS/Organizations/Organization.ts +4 -1
  87. package/src/AWS/Organizations/OrganizationResourcePolicy.ts +4 -1
  88. package/src/AWS/Organizations/OrganizationalUnit.ts +4 -1
  89. package/src/AWS/Organizations/Policy.ts +4 -1
  90. package/src/AWS/Organizations/PolicyAttachment.ts +4 -1
  91. package/src/AWS/Organizations/Root.ts +4 -1
  92. package/src/AWS/Organizations/RootPolicyType.ts +4 -1
  93. package/src/AWS/Organizations/TrustedServiceAccess.ts +4 -1
  94. package/src/AWS/Providers.ts +484 -438
  95. package/src/AWS/RDS/DBCluster.ts +4 -1
  96. package/src/AWS/RDS/DBClusterEndpoint.ts +4 -1
  97. package/src/AWS/RDS/DBClusterParameterGroup.ts +4 -1
  98. package/src/AWS/RDS/DBInstance.ts +4 -1
  99. package/src/AWS/RDS/DBParameterGroup.ts +4 -1
  100. package/src/AWS/RDS/DBProxy.ts +4 -1
  101. package/src/AWS/RDS/DBProxyEndpoint.ts +4 -1
  102. package/src/AWS/RDS/DBProxyTargetGroup.ts +4 -1
  103. package/src/AWS/RDS/DBSubnetGroup.ts +4 -1
  104. package/src/AWS/Route53/Record.ts +4 -1
  105. package/src/AWS/S3/Bucket.ts +3 -1
  106. package/src/AWS/SNS/Subscription.ts +4 -1
  107. package/src/AWS/SNS/Topic.ts +4 -1
  108. package/src/AWS/SQS/Queue.ts +3 -1
  109. package/src/AWS/Scheduler/Schedule.ts +4 -1
  110. package/src/AWS/Scheduler/ScheduleGroup.ts +4 -1
  111. package/src/AWS/SecretsManager/Secret.ts +4 -1
  112. package/src/AWS/Website/AssetDeployment.ts +4 -1
  113. package/src/Apply.ts +3 -3
  114. package/src/Binding.ts +18 -17
  115. package/src/Cloudflare/Container/ContainerApplication.ts +3 -1
  116. package/src/Cloudflare/D1/D1Database.ts +4 -1
  117. package/src/Cloudflare/KV/KVNamespace.ts +7 -4
  118. package/src/Cloudflare/Providers.ts +62 -60
  119. package/src/Cloudflare/R2/R2Bucket.ts +4 -1
  120. package/src/Cloudflare/R2/R2BucketBinding.ts +26 -31
  121. package/src/Cloudflare/Workers/Worker.ts +3 -1
  122. package/src/Cloudflare/Workers/Workflow.ts +3 -1
  123. package/src/Plan.ts +595 -596
  124. package/src/Platform.ts +9 -8
  125. package/src/Provider.ts +145 -23
  126. package/src/Resource.ts +10 -3
  127. package/src/Stack.ts +1 -1
  128. package/src/Util/service.ts +1 -1
  129. package/src/index.ts +10 -7
package/src/Platform.ts CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  } from "./ExecutionContext.ts";
14
14
  import type { HttpEffect } from "./Http.ts";
15
15
  import type { InputProps } from "./Input.ts";
16
- import type { Provider } from "./Provider.ts";
16
+ import type { Provider, ProviderCollectionLike } from "./Provider.ts";
17
17
  import { Resource, type ResourceLike } from "./Resource.ts";
18
18
  import { Self } from "./Self.ts";
19
19
  import type { Stack, StackServices } from "./Stack.ts";
@@ -42,6 +42,7 @@ export type PlatformServices =
42
42
  | HttpClient
43
43
  | PolicyLike
44
44
  | Provider<any>
45
+ | ProviderCollectionLike
45
46
  | Scope
46
47
  | Stack
47
48
  | StackServices
@@ -70,14 +71,14 @@ export interface Platform<
70
71
  ): Effect.Effect<
71
72
  Resource & Rpc<Self>,
72
73
  never,
73
- Self | Provider<Resource> | PropsReq
74
+ Self | Resource["Providers"] | PropsReq
74
75
  > & {
75
76
  make<InitReq = never>(
76
77
  impl: Effect.Effect<Shape, never, InitReq>,
77
78
  ): Layer.Layer<
78
79
  Self,
79
80
  never,
80
- | Provider<Resource>
81
+ | Resource["Providers"]
81
82
  | Exclude<PropsReq | InitReq, Services | PlatformServices>
82
83
  >;
83
84
  new (_: never): MakeShape<Shape, BaseShape>;
@@ -98,7 +99,7 @@ export interface Platform<
98
99
  ): Effect.Effect<
99
100
  Resource & Rpc<Self>,
100
101
  never,
101
- | Provider<Resource>
102
+ | Resource["Providers"]
102
103
  | PropsReq
103
104
  | Exclude<InitReq, Services | PlatformServices>
104
105
  > & {
@@ -112,14 +113,14 @@ export interface Platform<
112
113
  ): Effect.Effect<
113
114
  Resource & Rpc<Self>,
114
115
  never,
115
- Provider<Resource> | PropsReq
116
+ Resource["Providers"] | PropsReq
116
117
  > & {
117
118
  make<InitReq extends Services | PlatformServices = never>(
118
119
  impl: Effect.Effect<Shape, never, InitReq>,
119
120
  ): Layer.Layer<
120
121
  Self,
121
122
  never,
122
- | Provider<Resource>
123
+ | Resource["Providers"]
123
124
  | Exclude<PropsReq | InitReq, Services | PlatformServices>
124
125
  >;
125
126
  new (_: never): MakeShape<Shape, BaseShape>;
@@ -128,7 +129,7 @@ export interface Platform<
128
129
  ) => Effect.Effect<
129
130
  Resource & Rpc<Self>,
130
131
  never,
131
- | Provider<Resource>
132
+ | Resource["Providers"]
132
133
  | PropsReq
133
134
  | Exclude<InitReq, Services | PlatformServices>
134
135
  >);
@@ -141,7 +142,7 @@ export interface Platform<
141
142
  // ): Effect.Effect<
142
143
  // Resource,
143
144
  // never,
144
- // | Provider<Resource>
145
+ // | Resource["Providers"]
145
146
  // | PropsReq
146
147
  // | Exclude<InitReq, Services | PlatformServices>
147
148
  // >;
package/src/Provider.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  import * as Context from "effect/Context";
2
2
  import * as Effect from "effect/Effect";
3
3
  import * as Layer from "effect/Layer";
4
+ import * as Option from "effect/Option";
4
5
  import type * as Stream from "effect/Stream";
5
6
  import type { Artifacts } from "./Artifacts.ts";
7
+ import type { Policy } from "./Binding.ts";
6
8
  import type { ScopedPlanStatusSession } from "./Cli/index.ts";
7
9
  import type { Diff } from "./Diff.ts";
8
10
  import type { Input } from "./Input.ts";
@@ -27,16 +29,19 @@ export interface Provider<R extends ResourceLike = ResourceLike> {
27
29
  TailReq = never,
28
30
  LogsReq = never,
29
31
  >(
30
- service: ProviderService<
31
- R,
32
- ReadReq,
33
- DiffReq,
34
- PrecreateReq,
35
- CreateReq,
36
- UpdateReq,
37
- DeleteReq,
38
- TailReq,
39
- LogsReq
32
+ service: Omit<
33
+ ProviderService<
34
+ R,
35
+ ReadReq,
36
+ DiffReq,
37
+ PrecreateReq,
38
+ CreateReq,
39
+ UpdateReq,
40
+ DeleteReq,
41
+ TailReq,
42
+ LogsReq
43
+ >,
44
+ "Type"
40
45
  >,
41
46
  ) => ProviderService<
42
47
  R,
@@ -178,19 +183,6 @@ export interface ProviderService<
178
183
  }): Effect.Effect<void, any, DeleteReq>;
179
184
  }
180
185
 
181
- export const getProviderByType = Effect.fnUntraced(function* <
182
- R extends ResourceLike,
183
- >(resourceType: string) {
184
- const context = yield* Effect.context<never>();
185
- const provider: ProviderService<R> = context.mapUnsafe.get(resourceType);
186
- if (!provider) {
187
- return yield* Effect.die(
188
- new Error(`Provider not found for ${resourceType}`),
189
- );
190
- }
191
- return provider;
192
- });
193
-
194
186
  export const effect = <
195
187
  R extends ResourceLike,
196
188
  Req = never,
@@ -263,3 +255,133 @@ export const succeed = <
263
255
  > =>
264
256
  // @ts-expect-error
265
257
  Layer.succeed(Provider(cls.Type), service);
258
+
259
+ export interface ProviderCollectionLike {
260
+ kind: "ProviderCollection";
261
+ }
262
+
263
+ export interface ProviderCollectionShape<Identifier extends string>
264
+ extends
265
+ Context.ServiceClass.Shape<Identifier, ProviderCollectionService>,
266
+ ProviderCollectionLike {}
267
+
268
+ export interface ProviderCollection<Self, Identifier extends string>
269
+ extends
270
+ Context.Service<Self, ProviderCollectionService>,
271
+ ProviderCollectionLike {
272
+ readonly key: Identifier;
273
+ new (_: never): ProviderCollectionShape<Identifier>;
274
+ }
275
+
276
+ export const ProviderCollection =
277
+ <Self>() =>
278
+ <const ProviderId extends string>(id: ProviderId) =>
279
+ Context.Service<Self, ProviderCollectionService>()(
280
+ id,
281
+ ) as ProviderCollection<Self, ProviderId>;
282
+
283
+ export interface ProviderCollectionService {
284
+ kind: "ProviderCollection";
285
+ get<Resource extends ResourceLike>(
286
+ service: string,
287
+ ): ProviderService<Resource> | undefined;
288
+ }
289
+
290
+ export const collection = <
291
+ R extends
292
+ | ResourceClass<any>
293
+ | Platform<any, any, any, any, any>
294
+ | Policy<any, any, any>,
295
+ >(
296
+ resources: R[],
297
+ ): Effect.Effect<
298
+ ProviderCollectionService,
299
+ never,
300
+ R extends ResourceClass<infer R> | Platform<infer R, any, any, any, any>
301
+ ? Provider<R>
302
+ : R extends Policy<infer Self, infer _I, infer _S>
303
+ ? Self
304
+ : never
305
+ > =>
306
+ Effect.gen(function* () {
307
+ const context = yield* Effect.context();
308
+
309
+ const providers = Object.fromEntries(
310
+ yield* Effect.all(
311
+ resources.map((resource) =>
312
+ "Provider" in resource
313
+ ? resource.Provider.asEffect().pipe(
314
+ Effect.map((provider) => [resource.Type, provider] as const),
315
+ )
316
+ : Effect.succeed([
317
+ resource.key,
318
+ context.mapUnsafe.get(resource.key),
319
+ ] as const),
320
+ ),
321
+ { concurrency: "unbounded" },
322
+ ),
323
+ );
324
+
325
+ return {
326
+ kind: "ProviderCollection" as const,
327
+ get: (service: string) => providers[service],
328
+ };
329
+ }) as any;
330
+
331
+ const isProviderCollectionService = (
332
+ value: unknown,
333
+ ): value is ProviderCollectionService => {
334
+ return (
335
+ typeof value === "object" &&
336
+ value !== null &&
337
+ "kind" in value &&
338
+ value.kind === "ProviderCollection"
339
+ );
340
+ };
341
+
342
+ export const findProviderByType: {
343
+ <R extends ResourceLike>(
344
+ resourceType: R["Type"],
345
+ ): Effect.Effect<ProviderService<R>>;
346
+ <P extends Policy<any, any, any>>(
347
+ policyType: P["key"],
348
+ ): Effect.Effect<Effect.Success<P>>;
349
+ } = (type: string) =>
350
+ tryFindProviderByType(type).pipe(
351
+ Effect.flatMap(
352
+ Option.match({
353
+ onNone: () => Effect.die(`Provider not found for ${type}`),
354
+ onSome: (provider) => Effect.succeed(provider),
355
+ }),
356
+ ),
357
+ );
358
+
359
+ export const tryFindProviderByType: {
360
+ <R extends ResourceLike>(
361
+ resourceType: R["Type"],
362
+ ): Effect.Effect<Option.Option<ProviderService<R>>>;
363
+ <P extends Policy<any, any, any>>(
364
+ policyType: P["key"],
365
+ ): Effect.Effect<Option.Option<Effect.Success<P>>>;
366
+ } = Effect.fnUntraced(function* <R extends ResourceLike>(
367
+ resourceType: R["Type"],
368
+ ) {
369
+ const Tag = Provider<R>(resourceType) as Context.Service<Provider<R>, any>;
370
+ const direct = yield* Effect.serviceOption(Tag);
371
+ if (Option.isSome(direct)) {
372
+ return direct.value;
373
+ }
374
+
375
+ const context = yield* Effect.context<never>();
376
+ for (const value of context.mapUnsafe.values()) {
377
+ if (isProviderCollectionService(value)) {
378
+ const provider = value.get(resourceType);
379
+ if (provider) {
380
+ return Option.some(provider);
381
+ }
382
+ }
383
+ }
384
+
385
+ console.log(context.mapUnsafe.keys());
386
+ return Option.none();
387
+ }) as any;
package/src/Resource.ts CHANGED
@@ -40,7 +40,10 @@ export type ResourceConstructor<R extends ResourceLike, Req = never> = {
40
40
  export type ResourceClassWithMethods<
41
41
  R extends ResourceLike,
42
42
  Methods extends { [key: string]: any },
43
- > = ResourceConstructor<R, Provider<R>> &
43
+ > = ResourceConstructor<
44
+ R,
45
+ R["Providers"] extends undefined ? Provider<R> : R["Providers"]
46
+ > &
44
47
  Effect.Effect<ResourceConstructor<R>> & {
45
48
  Self: Self<R>;
46
49
  Provider: Provider<R>;
@@ -48,7 +51,7 @@ export type ResourceClassWithMethods<
48
51
 
49
52
  export type ResourceClass<R extends ResourceLike> = ResourceConstructor<
50
53
  R,
51
- Provider<R>
54
+ R["Providers"] extends undefined ? Provider<R> : R["Providers"]
52
55
  > &
53
56
  Effect.Effect<ResourceConstructor<R>> & {
54
57
  Self: Self<R>;
@@ -67,6 +70,7 @@ export interface ResourceLike<
67
70
  Props extends object | undefined = any,
68
71
  Attributes extends object = object,
69
72
  Binding = any,
73
+ Providers = any,
70
74
  > {
71
75
  /**
72
76
  * Namespace containing this Resource.
@@ -97,6 +101,8 @@ export interface ResourceLike<
97
101
  Attributes: Attributes;
98
102
  /** @internal phantom */
99
103
  Binding: Binding;
104
+ /** @internal phantom */
105
+ Providers: Providers;
100
106
  }
101
107
 
102
108
  export const isResource = (value: any): value is ResourceLike => {
@@ -108,8 +114,9 @@ export type Resource<
108
114
  Props extends object | undefined = any,
109
115
  Attributes extends object = any,
110
116
  Binding = never,
117
+ Providers = undefined,
111
118
  > = Pipeable &
112
- ResourceLike<Type, Props, Attributes, Binding> & {
119
+ ResourceLike<Type, Props, Attributes, Binding, Providers> & {
113
120
  bind(sid: string, binding: Input<Binding>): Effect.Effect<void>;
114
121
  bind(
115
122
  template: TemplateStringsArray,
package/src/Stack.ts CHANGED
@@ -146,9 +146,9 @@ export const make =
146
146
  Effect.map(
147
147
  ([output, stack, services]) =>
148
148
  ({
149
+ ...stack,
149
150
  output,
150
151
  services,
151
- ...stack,
152
152
  }) satisfies CompiledStack<A, ROut | StackServices> as CompiledStack<
153
153
  A,
154
154
  ROut | StackServices
@@ -6,7 +6,7 @@ export const GenericService =
6
6
  ...args: any[]
7
7
  ) => Context.Service<any, any>,
8
8
  >() =>
9
- <Kind extends string>(Kind: string): ReturnType<Fn> & Fn => {
9
+ <Kind extends string>(Kind: Kind): ReturnType<Fn> & Fn => {
10
10
  const service = Context.Service<any, any>(Kind);
11
11
  const make = (Type: string) => Context.Service(`${Kind}<${Type}>`);
12
12
  return Object.assign(
package/src/index.ts CHANGED
@@ -1,20 +1,23 @@
1
1
  export * as AdoptPolicy from "./AdoptPolicy.ts";
2
2
  export * from "./Apply.ts";
3
- export * as Binding from "./Binding.ts";
4
- export * as Build from "./Build/index.ts";
5
- export * as Bundle from "./Bundle/index.ts";
3
+ export {
4
+ Service as BindingService,
5
+ Policy,
6
+ type ServiceLike as BindingServiceLike,
7
+ type ServiceShape as BindingServiceShape,
8
+ type PolicyLike,
9
+ type PolicyShape,
10
+ } from "./Binding.ts";
6
11
  export * from "./Config.ts";
7
12
  export * from "./Destroy.ts";
8
13
  export * from "./Diff.ts";
9
- export * as Http from "./Http.ts";
10
14
  export * from "./Input.ts";
11
15
  export * from "./InstanceId.ts";
12
- export * as Kubernetes from "./Kubernetes/index.ts";
13
16
  export * from "./Namespace.ts";
14
- export * as Output from "./Output.ts";
17
+ export type { Output } from "./Output.ts";
15
18
  export * from "./PhysicalName.ts";
16
19
  export * as Plan from "./Plan.ts";
17
- export { Provider } from "./Provider.ts";
20
+ export { Provider, ProviderCollection } from "./Provider.ts";
18
21
  export * from "./Random.ts";
19
22
  export * from "./Ref.ts";
20
23
  export * as RemovalPolicy from "./RemovalPolicy.ts";