nomoss 0.0.3 → 0.0.4

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 (150) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +5 -15
  3. package/ROADMAP.md +2 -0
  4. package/docs/README.md +1 -1
  5. package/docs/application/aws-resource-coverage.md +26 -0
  6. package/docs/application/aws-resource-lifecycle-management.md +13 -23
  7. package/docs/application/cli-workflow.md +1 -1
  8. package/docs/application/engine-design.md +2 -2
  9. package/docs/application/generation-architecture.md +10 -45
  10. package/docs/application/resource-command-policy-stage.md +2 -2
  11. package/docs/application/resource-graph.md +1 -1
  12. package/docs/application/resource-lifecycle-tracker.md +1 -9
  13. package/docs/application/resource-mapping.md +4 -9
  14. package/docs/application/resource-operations.md +4 -2
  15. package/docs/application/tracing.md +2 -6
  16. package/docs/development/code-documentation.md +2 -0
  17. package/docs/development/effect-native-development.md +44 -0
  18. package/docs/development/linting.md +1 -1
  19. package/docs/development/review-code.md +22 -6
  20. package/docs/development/review-remediation-spec.md +28 -37
  21. package/docs/development/spec-writing.md +1 -1
  22. package/docs/development/testing.md +23 -9
  23. package/docs/operations/observability-sop.md +11 -17
  24. package/docs/operations/releasing.md +3 -1
  25. package/examples/README.md +3 -26
  26. package/examples/commands.ts +2 -36
  27. package/examples/queue/application.ts +8 -2
  28. package/examples/state-machine/application.ts +3 -1
  29. package/package.json +40 -46
  30. package/providers/aws/README.md +21 -0
  31. package/providers/aws/awsEnvironment.ts +114 -0
  32. package/providers/aws/generated/managementRegistry.ts +136 -0
  33. package/{src/providers/aws/resources/generated/native/apigatewayv2/api/index.ts → providers/aws/generated/resources/apigatewayv2/api.ts} +13 -50
  34. package/{src/providers/aws/resources/generated/native/apigatewayv2/integration/index.ts → providers/aws/generated/resources/apigatewayv2/integration.ts} +13 -37
  35. package/{src/providers/aws/resources/generated/native/apigatewayv2/route/index.ts → providers/aws/generated/resources/apigatewayv2/route.ts} +23 -40
  36. package/{src/providers/aws/resources/generated/native/apigatewayv2/stage/index.ts → providers/aws/generated/resources/apigatewayv2/stage.ts} +13 -38
  37. package/providers/aws/generated/resources/iam/accesskey.ts +184 -0
  38. package/{src/providers/aws/resources/generated/native/iam/group/index.ts → providers/aws/generated/resources/iam/group.ts} +13 -38
  39. package/{src/providers/aws/resources/generated/native/iam/grouppolicy/index.ts → providers/aws/generated/resources/iam/grouppolicy.ts} +29 -59
  40. package/{src/providers/aws/resources/generated/native/iam/instanceprofile/index.ts → providers/aws/generated/resources/iam/instanceprofile.ts} +13 -41
  41. package/{src/providers/aws/resources/generated/native/iam/managedpolicy/index.ts → providers/aws/generated/resources/iam/managedpolicy.ts} +13 -95
  42. package/providers/aws/generated/resources/iam/oidcprovider.ts +314 -0
  43. package/{src/providers/aws/resources/generated/native/iam/policy/index.ts → providers/aws/generated/resources/iam/policy.ts} +13 -28
  44. package/{src/providers/aws/resources/generated/native/iam/role/index.ts → providers/aws/generated/resources/iam/role.ts} +13 -47
  45. package/{src/providers/aws/resources/generated/native/iam/rolepolicy/index.ts → providers/aws/generated/resources/iam/rolepolicy.ts} +29 -59
  46. package/providers/aws/generated/resources/iam/samlprovider.ts +463 -0
  47. package/providers/aws/generated/resources/iam/servercertificate.ts +465 -0
  48. package/providers/aws/generated/resources/iam/servicelinkedrole.ts +187 -0
  49. package/{src/providers/aws/resources/generated/native/iam/user/index.ts → providers/aws/generated/resources/iam/user.ts} +13 -38
  50. package/{src/providers/aws/resources/generated/native/iam/userpolicy/index.ts → providers/aws/generated/resources/iam/userpolicy.ts} +29 -59
  51. package/{src/providers/aws/resources/generated/native/iam/usertogroupaddition/index.ts → providers/aws/generated/resources/iam/usertogroupaddition.ts} +13 -27
  52. package/providers/aws/generated/resources/iam/virtualmfadevice.ts +298 -0
  53. package/{src/providers/aws/resources/generated/native/kms/key/index.ts → providers/aws/generated/resources/kms/key.ts} +13 -41
  54. package/{src/providers/aws/resources/generated/native/lambda/function/index.ts → providers/aws/generated/resources/lambda/function.ts} +13 -63
  55. package/{src/providers/aws/resources/generated/native/lambda/permission/index.ts → providers/aws/generated/resources/lambda/permission.ts} +13 -55
  56. package/{src/providers/aws/resources/generated/native/s3/bucket/index.ts → providers/aws/generated/resources/s3/bucket.ts} +14 -104
  57. package/{src/providers/aws/resources/generated/native/sns/topic/index.ts → providers/aws/generated/resources/sns/topic.ts} +14 -29
  58. package/{src/providers/aws/resources/generated/native/sqs/queue/index.ts → providers/aws/generated/resources/sqs/queue.ts} +14 -38
  59. package/{src/providers/aws/resources/generated/native/stepfunctions/statemachine/index.ts → providers/aws/generated/resources/stepfunctions/statemachine.ts} +15 -58
  60. package/providers/aws/management/mappings/iam/group.ts +63 -0
  61. package/providers/aws/management/mappings/iam/iamIdentity.ts +41 -0
  62. package/providers/aws/management/mappings/iam/iamLifecycleSettings.ts +8 -0
  63. package/providers/aws/management/mappings/iam/inlinePolicies.ts +159 -0
  64. package/providers/aws/management/mappings/iam/instanceProfile.ts +77 -0
  65. package/providers/aws/management/mappings/iam/oidcProvider.ts +94 -0
  66. package/providers/aws/management/mappings/iam/role.ts +74 -0
  67. package/providers/aws/management/mappings/iam/samlProvider.ts +98 -0
  68. package/providers/aws/management/mappings/iam/serverCertificate.ts +72 -0
  69. package/providers/aws/management/mappings/iam/user.ts +61 -0
  70. package/providers/aws/management/mappings/iam/userToGroupAddition.ts +75 -0
  71. package/providers/aws/management/operations/iam/accessKey.ts +206 -0
  72. package/providers/aws/management/operations/iam/managedPolicy.ts +491 -0
  73. package/providers/aws/management/operations/iam/policy.ts +476 -0
  74. package/providers/aws/management/operations/iam/serviceLinkedRole.ts +172 -0
  75. package/providers/aws/management/operations/iam/virtualMfaDevice.ts +253 -0
  76. package/providers/aws/management/resourceAssociationConfiguration.ts +112 -0
  77. package/providers/aws/management/resourceAssociationRegistration.ts +349 -0
  78. package/providers/aws/management/resourceAssociations.ts +168 -0
  79. package/{src/providers → providers}/aws/management/resourceConfiguration.ts +24 -26
  80. package/providers/aws/management/resourceLifecycleRegistration.ts +540 -0
  81. package/providers/aws/management/resourceManagementModule.ts +31 -0
  82. package/providers/aws/management/resourceManagementRegistry.ts +62 -0
  83. package/providers/aws/management/resourceMapping.ts +84 -0
  84. package/providers/aws/management/resourceOperation.ts +134 -0
  85. package/providers/aws/management/resourceTagOperations.ts +108 -0
  86. package/providers/aws/management/resourceTiming.ts +4 -0
  87. package/providers/aws/runtime.ts +52 -0
  88. package/src/core/resource/resourceCommandPolicy.ts +20 -0
  89. package/src/core/resource/resourceLifecycle.ts +644 -0
  90. package/src/core/resource/resourceStabilization.ts +120 -0
  91. package/src/core/resource/resourceVersions.ts +102 -0
  92. package/src/core/stack/planner.ts +9 -0
  93. package/src/core/stack/resourceStackLifecycle.ts +36 -3
  94. package/src/core/state/resourceState.ts +6 -4
  95. package/src/core/state/stateStore.ts +57 -10
  96. package/src/providers/file/resourcePolicy.ts +13 -12
  97. package/src/providers/providerRuntimeLayer.ts +5 -2
  98. package/src/providers/resourceCommandPolicyLayer.ts +117 -37
  99. package/src/providers/stripe/management/resourcePolicy.ts +22 -11
  100. package/examples/http-echo/application.ts +0 -87
  101. package/src/providers/aws/client/awsClient.ts +0 -418
  102. package/src/providers/aws/client/awsClientConfig.ts +0 -133
  103. package/src/providers/aws/client/awsClientModel.ts +0 -119
  104. package/src/providers/aws/client/awsHttpOperation.ts +0 -153
  105. package/src/providers/aws/client/awsQueryOperation.ts +0 -149
  106. package/src/providers/aws/client/awsRequestSigner.ts +0 -115
  107. package/src/providers/aws/client/awsResponseDecoder.ts +0 -135
  108. package/src/providers/aws/client/awsRetryPolicy.ts +0 -62
  109. package/src/providers/aws/client/generated/apiGatewayV2.ts +0 -3025
  110. package/src/providers/aws/client/generated/cloudControl.ts +0 -5746
  111. package/src/providers/aws/client/generated/iam.ts +0 -10892
  112. package/src/providers/aws/client/generated/lambda.ts +0 -5403
  113. package/src/providers/aws/client/generated/sqs.ts +0 -3769
  114. package/src/providers/aws/client/generated/stepFunctions.ts +0 -1726
  115. package/src/providers/aws/client/openapi/cloudControl/CancelResourceRequest.json +0 -579
  116. package/src/providers/aws/client/openapi/cloudControl/CreateResource.json +0 -1019
  117. package/src/providers/aws/client/openapi/cloudControl/DeleteResource.json +0 -1018
  118. package/src/providers/aws/client/openapi/cloudControl/GetResource.json +0 -883
  119. package/src/providers/aws/client/openapi/cloudControl/GetResourceRequestStatus.json +0 -655
  120. package/src/providers/aws/client/openapi/cloudControl/ListResourceRequests.json +0 -566
  121. package/src/providers/aws/client/openapi/cloudControl/ListResources.json +0 -913
  122. package/src/providers/aws/client/openapi/cloudControl/UpdateResource.json +0 -1027
  123. package/src/providers/aws/cloudControl/client.ts +0 -69
  124. package/src/providers/aws/cloudControl/requestTracker.ts +0 -138
  125. package/src/providers/aws/cloudControl/resourceCommandPolicyLayer.ts +0 -63
  126. package/src/providers/aws/cloudControl/resourceLifecycle.ts +0 -479
  127. package/src/providers/aws/cloudControl/resources/generated/certificatemanager/certificate/index.ts +0 -179
  128. package/src/providers/aws/cloudControl/resources/generated/kms/key/index.ts +0 -362
  129. package/src/providers/aws/cloudControl/resources/generated/s3/bucket/index.ts +0 -2364
  130. package/src/providers/aws/cloudControl/resources/generated/sns/topic/index.ts +0 -326
  131. package/src/providers/aws/cloudControl/resources/generated/sqs/queue/index.ts +0 -307
  132. package/src/providers/aws/cloudControl/resources/generated/sqs/queueinlinepolicy/index.ts +0 -108
  133. package/src/providers/aws/cloudControl/runtime.ts +0 -127
  134. package/src/providers/aws/management/resourceMapping.ts +0 -343
  135. package/src/providers/aws/management/resourceOperation.ts +0 -57
  136. package/src/providers/aws/management/resourcePolicy.ts +0 -549
  137. package/src/providers/aws/management/resourceRegistration.ts +0 -294
  138. package/src/providers/aws/resources/apiGatewayV2/httpApi.ts +0 -327
  139. package/src/providers/aws/resources/generated/native/resourceCommands.ts +0 -152
  140. package/src/providers/aws/resources/iam/grant.ts +0 -150
  141. package/src/providers/aws/resources/iam/grantCommands.ts +0 -283
  142. package/src/providers/aws/resources/iam/policyDocument.ts +0 -30
  143. package/src/providers/aws/resources/iam/policyStatement.ts +0 -59
  144. package/src/providers/aws/resources/iam/role.ts +0 -426
  145. package/src/providers/aws/resources/iam/roleDeclaration.ts +0 -105
  146. package/src/providers/aws/resources/lambda/function.ts +0 -403
  147. package/src/providers/aws/resources/lambda/functionDeclaration.ts +0 -234
  148. package/src/providers/aws/resources/lambda/permission.ts +0 -363
  149. package/src/providers/aws/resources/stepFunctions/stateMachine.ts +0 -95
  150. package/src/providers/aws/runtime.ts +0 -70
@@ -1,108 +0,0 @@
1
- // Generated from the CloudFormation Registry resource schema. Do not edit.
2
- // biome-ignore-all lint/complexity/useRegexLiterals: Preserve Effect's generated regular expressions.
3
- import { Effect, Schema } from "effect";
4
- import {
5
- annotateResourceSchema,
6
- ResourceGraphBuilder,
7
- type ResourceInputJson,
8
- ResourceInputJsonSchema,
9
- type ResourceKey,
10
- ResourceSchemaAnnotationSchema,
11
- } from "nomoss/core";
12
-
13
- export interface QueueInlinePolicyProps {
14
- readonly PolicyDocument: {
15
- readonly [x: string]: ResourceInputJson;
16
- };
17
- readonly Queue: string;
18
- }
19
-
20
- export const QueueInlinePolicyResourceSchema =
21
- ResourceSchemaAnnotationSchema.make({
22
- provider: "aws",
23
- service: "sqs",
24
- resource: "queueinlinepolicy",
25
- operation: "create",
26
- stateSecretOutputKeys: [],
27
- cloudControl: {
28
- typeName: "AWS::SQS::QueueInlinePolicy",
29
- primaryIdentifier: ["/properties/Queue"],
30
- readOnlyProperties: [],
31
- createOnlyProperties: ["/properties/Queue"],
32
- writeOnlyProperties: [],
33
- },
34
- });
35
- export const QueueInlinePolicyPropsSchema = annotateResourceSchema(
36
- Schema.Struct({
37
- PolicyDocument: Schema.Record(
38
- Schema.String,
39
- ResourceInputJsonSchema.annotate({ expected: "JSON value" }),
40
- ).annotate({
41
- description:
42
- "A policy document that contains permissions to add to the specified SQS queue",
43
- }),
44
- Queue: Schema.String.annotate({ description: "The URL of the SQS queue." }),
45
- }),
46
- QueueInlinePolicyResourceSchema,
47
- );
48
-
49
- export type QueueInlinePolicyOutputs =
50
- typeof QueueInlinePolicyOutputsSchema.Type;
51
-
52
- export const QueueInlinePolicyOutputsSchema = Schema.Struct({});
53
-
54
- export interface QueueInlinePolicyResource {
55
- readonly key: ResourceKey;
56
- readonly props: QueueInlinePolicyProps;
57
- readonly outputs: {
58
- readonly [Key in keyof QueueInlinePolicyOutputs]-?: Required<QueueInlinePolicyOutputs>[Key];
59
- };
60
- }
61
-
62
- export const registerQueueInlinePolicy = Effect.fn(
63
- "QueueInlinePolicy.register",
64
- )(function* (input: {
65
- readonly key: ResourceKey;
66
- readonly props: QueueInlinePolicyProps;
67
- }) {
68
- const graph = yield* ResourceGraphBuilder;
69
- const graphResource = yield* graph.resource(input.key);
70
-
71
- const resourceProps: QueueInlinePolicyProps = yield* Schema.decodeEffect(
72
- QueueInlinePolicyPropsSchema,
73
- )(input.props);
74
-
75
- const resourceOutputs: QueueInlinePolicyOutputs = yield* Schema.decodeEffect(
76
- QueueInlinePolicyOutputsSchema,
77
- )({});
78
-
79
- yield* graphResource.register({
80
- propsSchema: QueueInlinePolicyPropsSchema,
81
- outputsSchema: QueueInlinePolicyOutputsSchema,
82
- props: resourceProps,
83
- outputs: resourceOutputs,
84
- });
85
-
86
- const resource: QueueInlinePolicyResource = {
87
- key: input.key,
88
- props: resourceProps,
89
- outputs: {},
90
- };
91
-
92
- return resource;
93
- });
94
- export const QueueInlinePolicyOutputCatalog = [
95
- {
96
- source: {
97
- provider: "AWS",
98
- service: "CloudFormation",
99
- name: "aws-sqs-queueinlinepolicy.json",
100
- format: "CloudFormation",
101
- },
102
- typeName: "AWS::SQS::QueueInlinePolicy",
103
- primaryIdentifier: ["/properties/Queue"],
104
- createOnlyProperties: ["/properties/Queue"],
105
- writeOnlyProperties: [],
106
- outputs: {},
107
- },
108
- ];
@@ -1,127 +0,0 @@
1
- import { Layer, Option } from "effect";
2
- import { FetchHttpClient, HttpClient } from "effect/http";
3
- import { resourceModelLayer } from "../../../core/resource/model.js";
4
- import { resourceStackRuntimeLayer } from "../../../core/runtime/stackRuntimeLayer.js";
5
- import { providerResourceCommandPolicyLayerLive } from "../../resourceCommandPolicyLayer.js";
6
- import {
7
- awsClientConfigurationLayerLive,
8
- awsClientLayer,
9
- } from "../client/awsClient.js";
10
- import {
11
- AwsClientConfig,
12
- AwsRegion,
13
- awsClientConfigLayer,
14
- } from "../client/awsClientConfig.js";
15
- import { AwsCloudControlClient } from "./client.js";
16
- import { AwsCloudControlRequestTracker } from "./requestTracker.js";
17
- import { awsCloudControlResourceCommandMetadataLayer } from "./resourceCommandPolicyLayer.js";
18
- import { AwsCloudControlResourceLifecycle } from "./resourceLifecycle.js";
19
-
20
- export const awsCloudControlClientLayer = Layer.effect(
21
- AwsCloudControlClient,
22
- AwsCloudControlClient.make,
23
- ).pipe(Layer.provideMerge(awsClientLayer));
24
-
25
- export const awsCloudControlClientLayerLive = awsCloudControlClientLayer.pipe(
26
- Layer.provide(awsClientConfigurationLayerLive),
27
- );
28
-
29
- /**
30
- * awsCloudControlResourceLifecycleLayer shares AWS invocation, generated
31
- * operations, and request tracking for resource execution. Applications and
32
- * tests can supply configuration and HTTP transport to the same assembly.
33
- */
34
- export const awsCloudControlResourceLifecycleLayer = Layer.effect(
35
- AwsCloudControlResourceLifecycle,
36
- AwsCloudControlResourceLifecycle.make,
37
- ).pipe(
38
- Layer.provideMerge(
39
- Layer.effect(
40
- AwsCloudControlRequestTracker,
41
- AwsCloudControlRequestTracker.make,
42
- ),
43
- ),
44
- Layer.provideMerge(awsCloudControlClientLayer),
45
- Layer.provideMerge(resourceModelLayer),
46
- );
47
-
48
- export const awsCloudControlResourceLifecycleLayerLive =
49
- awsCloudControlResourceLifecycleLayer.pipe(
50
- Layer.provide(awsClientConfigurationLayerLive),
51
- );
52
-
53
- /**
54
- * awsCloudControlResourceCommandLayer registers production Cloud Control
55
- * lifecycle operations for resource dispatch. Configuration and transport
56
- * remain dependencies for live applications and controlled HTTP tests.
57
- */
58
- export const awsCloudControlResourceCommandLayer =
59
- awsCloudControlResourceCommandMetadataLayer.pipe(
60
- Layer.provideMerge(awsCloudControlResourceLifecycleLayer),
61
- );
62
-
63
- export const awsCloudControlResourceCommandLayerLive =
64
- awsCloudControlResourceCommandLayer.pipe(
65
- Layer.provide(awsClientConfigurationLayerLive),
66
- );
67
-
68
- /**
69
- * awsCloudControlCommandPolicyLayer executes core resource commands through
70
- * the registered Cloud Control provider. Registrations remain available in the
71
- * output runtime because dispatch resolves them during command execution.
72
- */
73
- export const awsCloudControlCommandPolicyLayer =
74
- providerResourceCommandPolicyLayerLive.pipe(
75
- Layer.provideMerge(awsCloudControlResourceCommandLayer),
76
- );
77
-
78
- /**
79
- * awsCloudControlStackLayer combines AWS command execution with the production
80
- * stack runtime. Applications supply AWS configuration, HTTP transport, state
81
- * storage, and the secret policy. The Layer assembles the internal services.
82
- */
83
- export const awsCloudControlStackLayer = resourceStackRuntimeLayer.pipe(
84
- Layer.provideMerge(awsCloudControlCommandPolicyLayer),
85
- );
86
-
87
- export const awsCloudControlStackLayerLive = awsCloudControlStackLayer.pipe(
88
- Layer.provide(awsClientConfigurationLayerLive),
89
- );
90
-
91
- /**
92
- * The providers function applies configuration and HTTP transport to every
93
- * Cloud Control command in the application graph. Omitted services use
94
- * environment configuration and fetch. The region option overrides environment
95
- * configuration; a supplied clientConfig retains its own region. Compose the
96
- * returned Layer with the application's core services and storage.
97
- */
98
- export const providers = (
99
- options: {
100
- readonly region?: string;
101
- readonly clientConfig?: AwsClientConfig["Service"];
102
- readonly httpClient?: HttpClient.HttpClient;
103
- } = {},
104
- ) => {
105
- const configuration = Option.match(
106
- Option.fromUndefinedOr(options.clientConfig),
107
- {
108
- onNone: () => awsClientConfigLayer,
109
- onSome: (config) => Layer.succeed(AwsClientConfig, config),
110
- },
111
- ).pipe(
112
- Layer.provide(
113
- Layer.succeed(AwsRegion, Option.fromUndefinedOr(options.region)),
114
- ),
115
- );
116
-
117
- const transport = Option.match(Option.fromUndefinedOr(options.httpClient), {
118
- onNone: () => FetchHttpClient.layer,
119
- onSome: (http) => Layer.succeed(HttpClient.HttpClient, http),
120
- });
121
-
122
- const provider = awsCloudControlCommandPolicyLayer.pipe(
123
- Layer.provideMerge([configuration, transport]),
124
- );
125
-
126
- return provider;
127
- };
@@ -1,343 +0,0 @@
1
- import {
2
- Array as Arr,
3
- Context,
4
- Data,
5
- Effect,
6
- Layer,
7
- Match,
8
- Option,
9
- pipe,
10
- Record,
11
- Schema,
12
- Tuple,
13
- } from "effect";
14
- import { Digest } from "effect/crypto";
15
- import {
16
- ResourceModel,
17
- type ResourceNode,
18
- resourceModelLayer,
19
- } from "../../../core/resource/model.js";
20
- import { ResourceCommandStackName } from "../../../core/resource/resourceCommandPolicy.js";
21
- import { AwsJsonRpcPayload } from "../client/awsClientModel.js";
22
- import type {
23
- AwsAttributeResourceConfiguration,
24
- AwsResourceAttributeValues,
25
- AwsResourceProperties,
26
- AwsResourceState,
27
- } from "./resourceConfiguration.js";
28
-
29
- /**
30
- * The AwsResourceMappingFailed error identifies a declaration that cannot be
31
- * represented by its resource configuration. Lifecycle commands propagate this
32
- * failure before mutation so core retains the last successfully applied state.
33
- */
34
- export class AwsResourceMappingFailed extends Data.TaggedError(
35
- "AwsResourceMappingFailed",
36
- )<{
37
- readonly typeName: string;
38
- readonly message: string;
39
- }> {}
40
-
41
- /**
42
- * The AwsResourceMapping service validates declarations and reconstructed
43
- * resources against the original Registry schema. Native attribute and tag
44
- * values use the generated operation codecs. Physical naming and name recovery
45
- * follow SQS's URL identity contract.
46
- */
47
- export class AwsResourceMapping extends Context.Service<AwsResourceMapping>()(
48
- "nomoss/providers/aws/management/resourceMapping/AwsResourceMapping",
49
- {
50
- make: Effect.gen(function* () {
51
- const model = yield* ResourceModel;
52
- const digest = yield* Digest.Digest;
53
- const json = Schema.fromJsonString(Schema.Json);
54
-
55
- /**
56
- * The attributesMatch service method checks whether a provider read has
57
- * reached the requested settings. String properties compare literally.
58
- * JSON properties compare by value because AWS can change policy formatting.
59
- * An absent attribute satisfies an explicit empty-string removal.
60
- */
61
- const attributesMatch = (
62
- definition: AwsAttributeResourceConfiguration,
63
- expected: AwsResourceAttributeValues,
64
- actual: AwsResourceAttributeValues,
65
- ) => {
66
- const encodings = Record.mapEntries(
67
- definition.mapping.attributes,
68
- ({ attribute }, property) =>
69
- Tuple.make(attribute, definition.encodings[property]),
70
- );
71
- const equal = Schema.toEquivalence(Schema.Json);
72
- const matches: boolean = Record.every(expected, (value, attribute) => {
73
- const observed = actual[attribute] ?? "";
74
- return Match.value(encodings[attribute]).pipe(
75
- Match.when("string", () => value === observed),
76
- Match.orElse(() => {
77
- const desired = Schema.decodeUnknownOption(json)(value).pipe(
78
- Option.getOrElse(() => value),
79
- );
80
- const actualValue = Schema.decodeUnknownOption(json)(
81
- observed,
82
- ).pipe(Option.getOrElse(() => observed));
83
- return equal(desired, actualValue);
84
- }),
85
- );
86
- });
87
-
88
- return matches;
89
- };
90
-
91
- /**
92
- * The encodeAttributes service method converts declared settings to native
93
- * string values. JSON policy strings retain their existing representation.
94
- * numeric, boolean, and object values use Effect's JSON codec.
95
- */
96
- const encodeAttributes = Effect.fn("AwsResourceMapping.encodeAttributes")(
97
- function* (
98
- definition: AwsAttributeResourceConfiguration,
99
- properties: AwsJsonRpcPayload,
100
- ) {
101
- const selected = Record.filter(properties, (_, property) =>
102
- Record.has(definition.mapping.attributes, property),
103
- );
104
- const entries = yield* Effect.forEach(
105
- Record.toEntries(selected),
106
- Effect.fnUntraced(function* ([property, value]) {
107
- const encoded = yield* Match.value(value).pipe(
108
- Match.when(Match.string, (value) => Effect.succeed(value)),
109
- Match.orElse(Schema.encodeEffect(json)),
110
- );
111
- return Tuple.make(
112
- definition.mapping.attributes[property].attribute,
113
- encoded,
114
- );
115
- }),
116
- );
117
- const attributes: AwsResourceAttributeValues =
118
- yield* Schema.decodeEffect(definition.attributeSchema)(
119
- Record.fromEntries(entries),
120
- );
121
-
122
- return attributes;
123
- },
124
- );
125
-
126
- /**
127
- * The prepare service method validates a resolved declaration and supplies
128
- * its native attributes and managed tags. Duplicate tag keys fail because
129
- * a native map cannot retain both values from that declaration.
130
- */
131
- const prepare = Effect.fn("AwsResourceMapping.prepare")(function* (
132
- definition: AwsAttributeResourceConfiguration,
133
- node: ResourceNode,
134
- ) {
135
- const declared = yield* model.decodeProps(node, definition.propsSchema);
136
- const properties =
137
- yield* Schema.decodeUnknownEffect(AwsJsonRpcPayload)(declared);
138
- const attributes = yield* encodeAttributes(definition, properties);
139
-
140
- // The prepare operation retains the original tag list until duplicate
141
- // detection completes. A map alone cannot reveal that two declaration
142
- // entries supplied different values for the same key.
143
- const declaredTags = yield* Schema.decodeUnknownEffect(
144
- definition.tagsSchema,
145
- )(properties[definition.mapping.tags.property] ?? []);
146
- const tagValues = Record.fromIterableWith(
147
- declaredTags,
148
- ({ Key, Value }) => Tuple.make(Key, Value),
149
- );
150
- yield* Effect.fail(
151
- new AwsResourceMappingFailed({
152
- typeName: definition.mapping.typeName,
153
- message: "Tag keys must be unique",
154
- }),
155
- ).pipe(
156
- Effect.when(
157
- Effect.succeed(Record.size(tagValues) !== declaredTags.length),
158
- ),
159
- );
160
- const tags = yield* Schema.decodeEffect(definition.tagMapSchema)(
161
- tagValues,
162
- );
163
- const prepared: AwsResourceProperties = {
164
- properties,
165
- attributes,
166
- tags,
167
- };
168
-
169
- return prepared;
170
- });
171
-
172
- /**
173
- * The generatePhysicalName service method lets creation retries address
174
- * the same queue. Its digest includes the stack and create-only values so
175
- * separate stacks and replacement generations receive different names.
176
- */
177
- const generatePhysicalName = Effect.fn(
178
- "AwsResourceMapping.generatePhysicalName",
179
- )(function* (
180
- definition: AwsAttributeResourceConfiguration,
181
- node: ResourceNode,
182
- properties: AwsJsonRpcPayload,
183
- ) {
184
- const stackName = yield* ResourceCommandStackName;
185
- const owner = yield* Effect.fromOption(stackName);
186
- const createOnly = Record.filter(properties, (_, property) =>
187
- Arr.contains(definition.createOnlyProperties, property),
188
- );
189
- const seed = yield* Schema.encodeEffect(json)([
190
- owner,
191
- node.key.logicalId,
192
- definition.mapping.typeName,
193
- createOnly,
194
- ]);
195
- const hash = yield* digest.digestHex(
196
- Digest.sha256,
197
- new TextEncoder().encode(seed),
198
- );
199
-
200
- // The generatePhysicalName operation reserves room for the required
201
- // .fifo suffix within SQS's 80-character queue-name limit.
202
- const prefix = node.key.logicalId
203
- .replace(/[^a-zA-Z0-9_-]/g, "-")
204
- .substring(0, 40);
205
- const fifo = Option.fromUndefinedOr(
206
- definition.mapping.name.fifoProperty,
207
- ).pipe(Option.exists((property) => properties[property] === true));
208
- const suffix = Match.value(fifo).pipe(
209
- Match.when(true, () => ".fifo"),
210
- Match.orElse(() => ""),
211
- );
212
- const name: string = `${prefix}-${hash.substring(0, 24)}${suffix}`;
213
-
214
- return name;
215
- });
216
-
217
- /**
218
- * The physicalName service method preserves an application's explicit name
219
- * or derives a retry-stable name. Derivation requires the owning stack
220
- * supplied by core when it executes a planned mutation.
221
- */
222
- const physicalName = Effect.fn("AwsResourceMapping.physicalName")(
223
- function* (
224
- definition: AwsAttributeResourceConfiguration,
225
- node: ResourceNode,
226
- properties: AwsJsonRpcPayload,
227
- ) {
228
- const name: string = yield* Record.get(
229
- properties,
230
- definition.mapping.name.property,
231
- ).pipe(
232
- Option.match({
233
- onSome: Schema.decodeUnknownEffect(Schema.NonEmptyString),
234
- onNone: () => generatePhysicalName(definition, node, properties),
235
- }),
236
- );
237
-
238
- return name;
239
- },
240
- );
241
-
242
- /**
243
- * The decodeResource service method reconstructs the resource that core
244
- * saves after an AWS read. Missing output aliases fail, and the complete
245
- * writable properties must satisfy the original Registry schema.
246
- */
247
- const decodeResource = Effect.fn("AwsResourceMapping.decodeResource")(
248
- function* (
249
- definition: AwsAttributeResourceConfiguration,
250
- identity: string,
251
- attributes: AwsResourceAttributeValues,
252
- tags: AwsResourceAttributeValues,
253
- ) {
254
- // The decodeResource operation treats empty policy attributes as absent
255
- // properties because SQS uses an empty string to clear a policy.
256
- const selected = Record.filter(
257
- definition.mapping.attributes,
258
- ({ attribute }) =>
259
- Record.has(attributes, attribute) && attributes[attribute] !== "",
260
- );
261
- const values = yield* Effect.forEach(
262
- Record.toEntries(selected),
263
- Effect.fnUntraced(function* ([property, { attribute }]) {
264
- const value = attributes[attribute];
265
- const decoded = yield* Match.value(
266
- definition.encodings[property],
267
- ).pipe(
268
- Match.when("string", () => Effect.succeed(value)),
269
- Match.orElse(() => Schema.decodeEffect(json)(value)),
270
- );
271
- return Tuple.make(property, decoded);
272
- }),
273
- );
274
- const outputs = yield* Effect.forEach(
275
- Record.toEntries(definition.mapping.outputAttributes),
276
- Effect.fnUntraced(function* ([property, attribute]) {
277
- const value = yield* Schema.decodeUnknownEffect(
278
- Schema.NonEmptyString,
279
- )(attributes[attribute]);
280
- return Tuple.make(property, value);
281
- }),
282
- );
283
-
284
- // The decodeResource operation recovers QueueName from QueueUrl because
285
- // GetQueueAttributes omits the name. Effect codecs reject malformed URLs
286
- // and invalid URI escapes before the resource model is reconstructed.
287
- const url = yield* Schema.decodeEffect(Schema.URLFromString)(
288
- identity,
289
- );
290
- const segment = yield* Arr.last(url.pathname.split("/")).pipe(
291
- Effect.fromOption,
292
- );
293
- const decodedName = yield* Schema.decodeEffect(
294
- Schema.StringFromUriComponent,
295
- )(segment);
296
- const name = yield* Schema.decodeEffect(Schema.NonEmptyString)(
297
- decodedName,
298
- );
299
- const tagList = Arr.map(Record.toEntries(tags), ([Key, Value]) => ({
300
- Key,
301
- Value,
302
- }));
303
- const properties: AwsJsonRpcPayload = pipe(
304
- Record.fromEntries(values),
305
- Record.set(definition.mapping.name.property, name),
306
- Record.set(definition.mapping.tags.property, tagList),
307
- );
308
- yield* Schema.decodeUnknownEffect(
309
- Schema.toType(definition.propsSchema),
310
- )(properties);
311
-
312
- const projected = Record.union(
313
- properties,
314
- Record.fromEntries(outputs),
315
- (_, output) => output,
316
- );
317
- const resource: AwsJsonRpcPayload = Record.set(
318
- projected,
319
- definition.mapping.identity.property,
320
- identity,
321
- );
322
- const state: AwsResourceState = { resource, attributes, tags };
323
-
324
- return state;
325
- },
326
- );
327
-
328
- return {
329
- prepare,
330
- encodeAttributes,
331
- generatePhysicalName,
332
- physicalName,
333
- decodeResource,
334
- attributesMatch,
335
- };
336
- }),
337
- },
338
- ) {}
339
-
340
- export const awsResourceMappingLayer = Layer.effect(
341
- AwsResourceMapping,
342
- AwsResourceMapping.make,
343
- ).pipe(Layer.provide(resourceModelLayer));
@@ -1,57 +0,0 @@
1
- import { Effect, Schema, SchemaGetter } from "effect";
2
- import type {
3
- AwsJsonRpcPayload,
4
- AwsOperation,
5
- } from "../client/awsClientModel.js";
6
-
7
- type Operation<Input, Output, Encoded = unknown> = AwsOperation & {
8
- readonly input: Schema.Codec<Input, AwsJsonRpcPayload>;
9
- readonly output: Schema.Codec<Output, Encoded>;
10
- };
11
-
12
- /**
13
- * The resourceRequest function lets callers pass resource properties to a
14
- * generated AWS operation. Encoding translates the properties into AWS
15
- * fields and validates them against the original request schema.
16
- *
17
- * @see ../../../../../command-options-fund/refs/effect-website/apps/web/src/content/docs/v4/schema/transformations.mdx#understanding-input-and-output
18
- */
19
- export const resourceRequest = <Input, NativeInput, Output, Encoded>(
20
- operation: Operation<NativeInput, Output, Encoded>,
21
- codec: Schema.Codec<Input, NoInfer<NativeInput>>,
22
- ) => ({
23
- ...operation,
24
- input: operation.input.pipe(
25
- Schema.decodeTo(codec, {
26
- decode: SchemaGetter.forbidden(
27
- () => "Use the native schema to decode an AWS request",
28
- ),
29
- encode: SchemaGetter.passthrough(),
30
- }),
31
- ),
32
- });
33
-
34
- /**
35
- * The resourceResponse function validates the full AWS reply before
36
- * projecting resource outputs. The projection can require an identity that
37
- * the AWS response model marks optional. The operation fails if AWS omits
38
- * that identity.
39
- *
40
- * @see ../../../../../command-options-fund/refs/effect-website/apps/web/src/content/docs/v4/schema/transformations.mdx#understanding-input-and-output
41
- */
42
- export const resourceResponse = <Input, NativeOutput, Encoded, Output, Fields>(
43
- operation: Operation<Input, NativeOutput, Encoded>,
44
- codec: Schema.Codec<Output, Fields>,
45
- ) => ({
46
- ...operation,
47
- output: operation.output.pipe(
48
- Schema.decodeTo(Schema.toType(codec), {
49
- decode: SchemaGetter.transformEffect((value: NativeOutput) =>
50
- Schema.decodeUnknownEffect(codec)(value).pipe(
51
- Effect.mapError((failure) => failure.issue),
52
- ),
53
- ),
54
- encode: SchemaGetter.forbiddenEncoding,
55
- }),
56
- ),
57
- });