nomoss 0.0.1
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.
- package/LICENSE +19 -0
- package/README.md +45 -0
- package/bin/nomoss +13 -0
- package/docs/code-documentation.md +36 -0
- package/docs/effect-native-development.md +55 -0
- package/docs/engine-design.md +93 -0
- package/docs/linting.md +88 -0
- package/docs/releasing.md +13 -0
- package/docs/resource-command-policy-stage.md +71 -0
- package/docs/resource-graph-mvp.md +31 -0
- package/docs/resource-graph-testing-approach.md +11 -0
- package/docs/resource-lifecycle-tracker.md +93 -0
- package/docs/testing.md +86 -0
- package/examples/upload-events/README.md +41 -0
- package/media/nomoss.gif +0 -0
- package/package.json +64 -0
- package/src/cli.ts +18 -0
- package/src/cliCommand.ts +186 -0
- package/src/cliRuntimeLayer.ts +49 -0
- package/src/core/index.ts +17 -0
- package/src/core/lifecycle.ts +127 -0
- package/src/core/model.ts +229 -0
- package/src/core/physicalNameStore.ts +226 -0
- package/src/core/planner.ts +645 -0
- package/src/core/resourceCommandPolicy.ts +79 -0
- package/src/core/resourceGraphBuilder.ts +167 -0
- package/src/core/resourceGraphStore.ts +288 -0
- package/src/core/resourceOutputResolver.ts +185 -0
- package/src/core/resourcePolicy.ts +77 -0
- package/src/core/resourceStackDefinition.ts +17 -0
- package/src/core/resourceStackLifecycle.ts +456 -0
- package/src/core/resourceStackOperations.ts +129 -0
- package/src/core/runtimeLayer.ts +73 -0
- package/src/core/stackWorkflowRenderer.ts +239 -0
- package/src/core/stateSecretService.ts +553 -0
- package/src/core/stateStore.ts +652 -0
- package/src/core/tracing.ts +26 -0
- package/src/index.ts +2 -0
- package/src/providers/aws/awsApply.ts +132 -0
- package/src/providers/aws/awsBucket.ts +329 -0
- package/src/providers/aws/awsBucketNotification.ts +351 -0
- package/src/providers/aws/awsBucketNotificationResourcePolicy.ts +251 -0
- package/src/providers/aws/awsBucketResourcePolicy.ts +198 -0
- package/src/providers/aws/awsProviderLayer.ts +274 -0
- package/src/providers/aws/awsQueue.ts +346 -0
- package/src/providers/aws/awsQueuePolicy.ts +419 -0
- package/src/providers/aws/awsQueuePolicyResourcePolicy.ts +215 -0
- package/src/providers/aws/awsQueueResourcePolicy.ts +270 -0
- package/src/providers/aws/awsReconciliation.ts +92 -0
- package/src/providers/aws/awsRefresh.ts +50 -0
- package/src/providers/aws/awsResourceLifecycle.ts +118 -0
- package/src/providers/aws/awsResourcePolicy.ts +83 -0
- package/src/providers/aws/awsResources.ts +274 -0
- package/src/providers/aws/awsRuntimeLayer.ts +21 -0
- package/src/providers/aws/awsSqsTransport.ts +33 -0
- package/src/providers/aws/awsStackLifecycle.ts +272 -0
- package/src/providers/aws/awsTagging.ts +186 -0
- package/src/providers/aws/constants.ts +3 -0
- package/src/providers/aws/index.ts +22 -0
- package/src/providers/aws/sampleStack.ts +65 -0
- package/src/providers/aws/stackWorkflow.ts +443 -0
- package/src/providers/index.ts +5 -0
- package/src/providers/provider.ts +5 -0
- package/src/providers/providerRuntimeLayer.ts +121 -0
- package/src/providers/resourceCommandPolicyLayer.ts +240 -0
- package/src/providers/stripe/index.ts +15 -0
- package/src/providers/stripe/stripeAccount.ts +139 -0
- package/src/providers/stripe/stripeBillingConfigurationExport.ts +180 -0
- package/src/providers/stripe/stripeBillingConfigurationExportResourcePolicy.ts +178 -0
- package/src/providers/stripe/stripeBillingPortalConfiguration.ts +153 -0
- package/src/providers/stripe/stripeBillingPortalConfigurationResourcePolicy.ts +177 -0
- package/src/providers/stripe/stripeCustomer.ts +148 -0
- package/src/providers/stripe/stripeCustomerResourcePolicy.ts +160 -0
- package/src/providers/stripe/stripePrice.ts +218 -0
- package/src/providers/stripe/stripePriceResourcePolicy.ts +151 -0
- package/src/providers/stripe/stripeProduct.ts +171 -0
- package/src/providers/stripe/stripeProductResourcePolicy.ts +161 -0
- package/src/providers/stripe/stripeResources.ts +454 -0
- package/src/providers/stripe/stripeRuntimeLayer.ts +131 -0
- package/src/providers/stripe/stripeWebhookEndpoint.ts +293 -0
- package/src/providers/stripe/stripeWebhookEndpointResourcePolicy.ts +198 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { type Cause, Context, Data, Effect, Match } from "effect";
|
|
2
|
+
|
|
3
|
+
import type { ResourceCommandResult as ResourceCommandResultValue } from "./lifecycle.js";
|
|
4
|
+
import {
|
|
5
|
+
PlanDecision,
|
|
6
|
+
type ResourceCommand,
|
|
7
|
+
ResourceCommandResult,
|
|
8
|
+
ResourceCommandUnsupported,
|
|
9
|
+
} from "./lifecycle.js";
|
|
10
|
+
|
|
11
|
+
export type ResourceCommandFailure = Cause.YieldableError & {
|
|
12
|
+
readonly _tag: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Provider dispatch preserves a typed provider failure for lifecycle state
|
|
17
|
+
* recording instead of reducing it to an unstructured cause.
|
|
18
|
+
*/
|
|
19
|
+
export class ResourceCommandExecutionFailed extends Data.TaggedError(
|
|
20
|
+
"ResourceCommandExecutionFailed",
|
|
21
|
+
)<{
|
|
22
|
+
readonly command: ResourceCommand;
|
|
23
|
+
readonly cause: ResourceCommandFailure;
|
|
24
|
+
}> {}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Provider packages satisfy this service with their resource command
|
|
28
|
+
* dispatcher. Core stack execution depends on this contract instead of
|
|
29
|
+
* importing provider implementations.
|
|
30
|
+
*/
|
|
31
|
+
export class ResourceCommandPolicy extends Context.Service<ResourceCommandPolicy>()(
|
|
32
|
+
"nomoss/core/resourceCommandPolicy",
|
|
33
|
+
{
|
|
34
|
+
make: Effect.succeed({
|
|
35
|
+
execute: Effect.fn("ResourceCommandPolicy.execute")(function* (
|
|
36
|
+
command: ResourceCommand,
|
|
37
|
+
) {
|
|
38
|
+
const fallbackResult = Match.value(command).pipe(
|
|
39
|
+
Match.tagsExhaustive({
|
|
40
|
+
Read: ({ node: readNode }) =>
|
|
41
|
+
ResourceCommandResult.Observed({
|
|
42
|
+
observation: {
|
|
43
|
+
_tag: "Missing",
|
|
44
|
+
node: readNode,
|
|
45
|
+
},
|
|
46
|
+
}),
|
|
47
|
+
Diff: ({ node: diffNode }) =>
|
|
48
|
+
ResourceCommandResult.Decided({
|
|
49
|
+
decision: PlanDecision.NoOp({ node: diffNode }),
|
|
50
|
+
}),
|
|
51
|
+
Apply: ({ decision }) =>
|
|
52
|
+
ResourceCommandResult.Decided({ decision }),
|
|
53
|
+
Create: ({ node: createdNode }) =>
|
|
54
|
+
ResourceCommandResult.Created({ node: createdNode }),
|
|
55
|
+
Update: ({ node: updatedNode }) =>
|
|
56
|
+
ResourceCommandResult.Updated({ node: updatedNode }),
|
|
57
|
+
Delete: ({ node: deletedNode }) =>
|
|
58
|
+
ResourceCommandResult.Deleted({ node: deletedNode }),
|
|
59
|
+
Destroy: ({ node: destroyedNode }) =>
|
|
60
|
+
ResourceCommandResult.Destroyed({ node: destroyedNode }),
|
|
61
|
+
}),
|
|
62
|
+
);
|
|
63
|
+
const commandResult: ResourceCommandResultValue = fallbackResult;
|
|
64
|
+
const result = yield* Effect.succeed(commandResult).pipe(
|
|
65
|
+
Effect.filterOrFail(
|
|
66
|
+
() => false,
|
|
67
|
+
() =>
|
|
68
|
+
new ResourceCommandExecutionFailed({
|
|
69
|
+
command,
|
|
70
|
+
cause: new ResourceCommandUnsupported({ command }),
|
|
71
|
+
}),
|
|
72
|
+
),
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
return result;
|
|
76
|
+
}),
|
|
77
|
+
}),
|
|
78
|
+
},
|
|
79
|
+
) {}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { Array as Arr, Context, Effect, Ref, Schema } from "effect";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type DependencyEdge,
|
|
5
|
+
type ResourceKey,
|
|
6
|
+
ResourceModel,
|
|
7
|
+
type ResourceOutputRef,
|
|
8
|
+
} from "./model.js";
|
|
9
|
+
import { ResourceGraphStore } from "./resourceGraphStore.js";
|
|
10
|
+
|
|
11
|
+
export type ResourceDependencyInput = {
|
|
12
|
+
readonly source: ResourceKey;
|
|
13
|
+
readonly target: ResourceKey;
|
|
14
|
+
readonly edge: DependencyEdge;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type ResourceDeclarationInput<
|
|
18
|
+
Props,
|
|
19
|
+
Outputs,
|
|
20
|
+
PropsSchema extends Schema.Schema<Props>,
|
|
21
|
+
OutputsSchema extends Schema.Schema<Outputs>,
|
|
22
|
+
> = {
|
|
23
|
+
readonly propsSchema: PropsSchema;
|
|
24
|
+
readonly outputsSchema: OutputsSchema;
|
|
25
|
+
readonly props: NoInfer<Props>;
|
|
26
|
+
readonly outputs: NoInfer<Outputs>;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Provider declarations consume output refs through this service so the graph
|
|
31
|
+
* records dependency edges at the same point where a resource needs another
|
|
32
|
+
* resource value.
|
|
33
|
+
*/
|
|
34
|
+
export class ResourceGraphBuilder extends Context.Service<ResourceGraphBuilder>()(
|
|
35
|
+
"nomoss/core/resourceGraphBuilder",
|
|
36
|
+
{
|
|
37
|
+
make: Effect.gen(function* () {
|
|
38
|
+
const graph = yield* ResourceGraphStore;
|
|
39
|
+
const model = yield* ResourceModel;
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
resource: Effect.fn("ResourceGraphBuilder.resource")(function* (
|
|
43
|
+
key: ResourceKey,
|
|
44
|
+
) {
|
|
45
|
+
const dependencies =
|
|
46
|
+
yield* Ref.make<ReadonlyArray<ResourceDependencyInput>>([]);
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
after: Effect.fn("ResourceGraphBuilder.resource.after")(function* (
|
|
50
|
+
source: ResourceKey,
|
|
51
|
+
property: string,
|
|
52
|
+
sourceProperty: string,
|
|
53
|
+
) {
|
|
54
|
+
const dependency: ResourceDependencyInput = {
|
|
55
|
+
source,
|
|
56
|
+
target: key,
|
|
57
|
+
edge: {
|
|
58
|
+
kind: "property",
|
|
59
|
+
property,
|
|
60
|
+
sourceProperty,
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
yield* Ref.update(dependencies, Arr.append(dependency));
|
|
65
|
+
}),
|
|
66
|
+
|
|
67
|
+
register: Effect.fn("ResourceGraphBuilder.resource.register")(
|
|
68
|
+
function* <
|
|
69
|
+
Props,
|
|
70
|
+
Outputs,
|
|
71
|
+
PropsSchema extends Schema.Schema<Props>,
|
|
72
|
+
OutputsSchema extends Schema.Schema<Outputs>,
|
|
73
|
+
>(
|
|
74
|
+
input: ResourceDeclarationInput<
|
|
75
|
+
Props,
|
|
76
|
+
Outputs,
|
|
77
|
+
PropsSchema,
|
|
78
|
+
OutputsSchema
|
|
79
|
+
>,
|
|
80
|
+
) {
|
|
81
|
+
const node = yield* model.nodeFromResource({
|
|
82
|
+
key,
|
|
83
|
+
propsSchema: input.propsSchema,
|
|
84
|
+
outputsSchema: input.outputsSchema,
|
|
85
|
+
props: input.props,
|
|
86
|
+
outputs: input.outputs,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
yield* graph.addResource(node);
|
|
90
|
+
yield* Ref.get(dependencies).pipe(
|
|
91
|
+
Effect.flatMap((resourceDependencies) =>
|
|
92
|
+
Effect.forEach(
|
|
93
|
+
resourceDependencies,
|
|
94
|
+
(dependency) =>
|
|
95
|
+
graph.addDependency(
|
|
96
|
+
dependency.source,
|
|
97
|
+
dependency.target,
|
|
98
|
+
dependency.edge,
|
|
99
|
+
),
|
|
100
|
+
{ discard: true },
|
|
101
|
+
),
|
|
102
|
+
),
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
return node;
|
|
106
|
+
},
|
|
107
|
+
),
|
|
108
|
+
|
|
109
|
+
valueFrom: Effect.fn("ResourceGraphBuilder.resource.valueFrom")(
|
|
110
|
+
function* <Value, ValueSchema extends Schema.Schema<Value>>(
|
|
111
|
+
output: ResourceOutputRef,
|
|
112
|
+
property: string,
|
|
113
|
+
schema: ValueSchema,
|
|
114
|
+
) {
|
|
115
|
+
const dependency: ResourceDependencyInput = {
|
|
116
|
+
source: output.source,
|
|
117
|
+
target: key,
|
|
118
|
+
edge: {
|
|
119
|
+
kind: "property",
|
|
120
|
+
property,
|
|
121
|
+
sourceProperty: output.property,
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
yield* Ref.update(dependencies, Arr.append(dependency));
|
|
126
|
+
const outputValue = yield* graph.outputValue(
|
|
127
|
+
output.source,
|
|
128
|
+
output.property,
|
|
129
|
+
);
|
|
130
|
+
const decodedOutput = yield* Schema.decodeUnknownEffect(schema)(
|
|
131
|
+
outputValue,
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
return decodedOutput;
|
|
135
|
+
},
|
|
136
|
+
),
|
|
137
|
+
|
|
138
|
+
stringFrom: Effect.fn("ResourceGraphBuilder.resource.stringFrom")(
|
|
139
|
+
function* (output: ResourceOutputRef, property: string) {
|
|
140
|
+
const dependency: ResourceDependencyInput = {
|
|
141
|
+
source: output.source,
|
|
142
|
+
target: key,
|
|
143
|
+
edge: {
|
|
144
|
+
kind: "property",
|
|
145
|
+
property,
|
|
146
|
+
sourceProperty: output.property,
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
yield* Ref.update(dependencies, Arr.append(dependency));
|
|
151
|
+
const outputValue = yield* graph.outputValue(
|
|
152
|
+
output.source,
|
|
153
|
+
output.property,
|
|
154
|
+
);
|
|
155
|
+
const outputString = yield* Schema.decodeUnknownEffect(
|
|
156
|
+
Schema.String,
|
|
157
|
+
)(outputValue);
|
|
158
|
+
|
|
159
|
+
return outputString;
|
|
160
|
+
},
|
|
161
|
+
),
|
|
162
|
+
};
|
|
163
|
+
}),
|
|
164
|
+
};
|
|
165
|
+
}),
|
|
166
|
+
},
|
|
167
|
+
) {}
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Array as Arr,
|
|
3
|
+
Context,
|
|
4
|
+
Data,
|
|
5
|
+
Effect,
|
|
6
|
+
Graph,
|
|
7
|
+
Option,
|
|
8
|
+
Ref,
|
|
9
|
+
Schema,
|
|
10
|
+
} from "effect";
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
type DependencyEdge,
|
|
14
|
+
keyString,
|
|
15
|
+
type ResourceKey,
|
|
16
|
+
ResourceModel,
|
|
17
|
+
type ResourceNode,
|
|
18
|
+
} from "./model.js";
|
|
19
|
+
|
|
20
|
+
type ResourceGraphState = {
|
|
21
|
+
readonly graph: Graph.DirectedGraph<ResourceNode, DependencyEdge>;
|
|
22
|
+
readonly indexByKey: ReadonlyMap<string, Graph.NodeIndex>;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Lifecycle code needs both the upstream resource key and the property mapping
|
|
27
|
+
* recorded on the graph edge. This shape keeps output resolution tied to the
|
|
28
|
+
* declaration graph instead of rediscovering dependencies from JSON props.
|
|
29
|
+
*/
|
|
30
|
+
export type ResourceDependency = {
|
|
31
|
+
readonly source: ResourceKey;
|
|
32
|
+
readonly target: ResourceKey;
|
|
33
|
+
readonly edge: DependencyEdge;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Graph readers fail with the logical resource key that was requested so
|
|
38
|
+
* planner, lifecycle, and diagnostics can report missing declarations without
|
|
39
|
+
* manufacturing an empty node.
|
|
40
|
+
*/
|
|
41
|
+
export class ResourceNotFound extends Data.TaggedError("ResourceNotFound")<{
|
|
42
|
+
readonly key: ResourceKey;
|
|
43
|
+
}> {}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Resource declarations must produce one node for each stable resource key.
|
|
47
|
+
* Duplicate detection protects graph topology before planning or lifecycle
|
|
48
|
+
* execution sees ambiguous nodes.
|
|
49
|
+
*/
|
|
50
|
+
export class DuplicateResource extends Data.TaggedError("DuplicateResource")<{
|
|
51
|
+
readonly key: ResourceKey;
|
|
52
|
+
}> {}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Stack declarations write nodes and property-derived edges here while planner
|
|
56
|
+
* and workflow code read the resulting topology through typed operations.
|
|
57
|
+
*/
|
|
58
|
+
export class ResourceGraphStore extends Context.Service<ResourceGraphStore>()(
|
|
59
|
+
"nomoss/core/resourceGraphStore",
|
|
60
|
+
{
|
|
61
|
+
make: Effect.gen(function* () {
|
|
62
|
+
const resourceModel = yield* ResourceModel;
|
|
63
|
+
const initialState: ResourceGraphState = {
|
|
64
|
+
graph: Graph.directed<ResourceNode, DependencyEdge>(),
|
|
65
|
+
indexByKey: new Map(),
|
|
66
|
+
};
|
|
67
|
+
const state = yield* Ref.make<ResourceGraphState>(initialState);
|
|
68
|
+
/**
|
|
69
|
+
* Effect's graph API addresses nodes by index, while Nomoss callers use
|
|
70
|
+
* resource keys. The side index is the service invariant that lets every
|
|
71
|
+
* operation resolve a declared resource through the same key path.
|
|
72
|
+
*/
|
|
73
|
+
const indexFor = (key: ResourceKey, graphState: ResourceGraphState) =>
|
|
74
|
+
Option.fromUndefinedOr(graphState.indexByKey.get(keyString(key))).pipe(
|
|
75
|
+
Option.match({
|
|
76
|
+
onNone: () => Effect.fail(new ResourceNotFound({ key })),
|
|
77
|
+
onSome: Effect.succeed,
|
|
78
|
+
}),
|
|
79
|
+
);
|
|
80
|
+
const nodeAt = (
|
|
81
|
+
graphState: ResourceGraphState,
|
|
82
|
+
key: ResourceKey,
|
|
83
|
+
index: Graph.NodeIndex,
|
|
84
|
+
) =>
|
|
85
|
+
Option.fromUndefinedOr(graphState.graph.nodes.get(index)).pipe(
|
|
86
|
+
Option.match({
|
|
87
|
+
onNone: () => Effect.fail(new ResourceNotFound({ key })),
|
|
88
|
+
onSome: Effect.succeed,
|
|
89
|
+
}),
|
|
90
|
+
);
|
|
91
|
+
const nodesFor = Effect.fn("ResourceGraphStore.nodesFor")(function* (
|
|
92
|
+
key: ResourceKey,
|
|
93
|
+
direction: Graph.Direction,
|
|
94
|
+
) {
|
|
95
|
+
const graphState = yield* Ref.get(state);
|
|
96
|
+
const nodeIndex = yield* indexFor(key, graphState);
|
|
97
|
+
const graphNodes = Arr.getSomes(
|
|
98
|
+
Arr.map(
|
|
99
|
+
Graph.neighborsDirected(graphState.graph, nodeIndex, direction),
|
|
100
|
+
(index) =>
|
|
101
|
+
Option.fromUndefinedOr(graphState.graph.nodes.get(index)),
|
|
102
|
+
),
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
return graphNodes;
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
return {
|
|
109
|
+
/**
|
|
110
|
+
* Stack preparation replays a declaration graph into this store. Each
|
|
111
|
+
* preparation starts from an empty graph so status and inspection calls
|
|
112
|
+
* can safely follow apply in the same application runtime.
|
|
113
|
+
*/
|
|
114
|
+
reset: Ref.set(state, initialState),
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Resource declaration services call this as each resource is declared.
|
|
118
|
+
* The duplicate check keeps the planning graph deterministic before
|
|
119
|
+
* dependency edges, topological planning, or lifecycle state are read.
|
|
120
|
+
*/
|
|
121
|
+
addResource: Effect.fn("ResourceGraphStore.addResource")(function* (
|
|
122
|
+
node: ResourceNode,
|
|
123
|
+
) {
|
|
124
|
+
const graphState = yield* Ref.get(state);
|
|
125
|
+
const stableKey = keyString(node.key);
|
|
126
|
+
yield* Effect.filterOrFail(
|
|
127
|
+
Effect.succeed(stableKey),
|
|
128
|
+
() => !graphState.indexByKey.has(stableKey),
|
|
129
|
+
() => new DuplicateResource({ key: node.key }),
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
let nodeIndex: Graph.NodeIndex = -1;
|
|
133
|
+
const nextGraph = Graph.mutate(graphState.graph, (mutable) => {
|
|
134
|
+
nodeIndex = Graph.addNode(mutable, node);
|
|
135
|
+
});
|
|
136
|
+
const indexEntries: ReadonlyArray<
|
|
137
|
+
readonly [string, Graph.NodeIndex]
|
|
138
|
+
> = Arr.append(Arr.fromIterable(graphState.indexByKey), [
|
|
139
|
+
stableKey,
|
|
140
|
+
nodeIndex,
|
|
141
|
+
]);
|
|
142
|
+
const nextState: ResourceGraphState = {
|
|
143
|
+
graph: nextGraph,
|
|
144
|
+
indexByKey: new Map(indexEntries),
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
yield* Ref.set(state, nextState);
|
|
148
|
+
}),
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Declaration-time `ResourceOutputRef` handling records the property
|
|
152
|
+
* relationship here. Planner code uses the edge for ordering, and stack
|
|
153
|
+
* lifecycle uses the same edge for output-value resolution immediately
|
|
154
|
+
* before provider execution.
|
|
155
|
+
*/
|
|
156
|
+
addDependency: Effect.fn("ResourceGraphStore.addDependency")(function* (
|
|
157
|
+
source: ResourceKey,
|
|
158
|
+
target: ResourceKey,
|
|
159
|
+
edge: DependencyEdge,
|
|
160
|
+
) {
|
|
161
|
+
const graphState = yield* Ref.get(state);
|
|
162
|
+
const sourceIndex = yield* indexFor(source, graphState);
|
|
163
|
+
const targetIndex = yield* indexFor(target, graphState);
|
|
164
|
+
const nextGraph = Graph.mutate(graphState.graph, (mutable) => {
|
|
165
|
+
Graph.addEdge(mutable, sourceIndex, targetIndex, edge);
|
|
166
|
+
});
|
|
167
|
+
const nextState: ResourceGraphState = {
|
|
168
|
+
graph: nextGraph,
|
|
169
|
+
indexByKey: graphState.indexByKey,
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
yield* Ref.set(state, nextState);
|
|
173
|
+
}),
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Planners and diagnostics use incoming resource nodes when they need
|
|
177
|
+
* topology without property-path metadata.
|
|
178
|
+
*/
|
|
179
|
+
dependenciesOf: (key: ResourceKey) => nodesFor(key, "incoming"),
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Destroy planning and graph inspection use outgoing resource nodes to
|
|
183
|
+
* find declarations that depend on a resource.
|
|
184
|
+
*/
|
|
185
|
+
dependentsOf: (key: ResourceKey) => nodesFor(key, "outgoing"),
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Stack lifecycle asks for dependency edges before create/update
|
|
189
|
+
* provider commands so `ResourceOutputResolver` can replace declared
|
|
190
|
+
* `ResourceOutputRef` props with outputs from the applied upstream
|
|
191
|
+
* resource state. The graph remains the source for which property paths
|
|
192
|
+
* require resolution; the resolver does not rediscover refs by walking
|
|
193
|
+
* arbitrary JSON props.
|
|
194
|
+
*/
|
|
195
|
+
dependencyEdgesOf: Effect.fn("ResourceGraphStore.dependencyEdgesOf")(
|
|
196
|
+
function* (key: ResourceKey) {
|
|
197
|
+
const graphState = yield* Ref.get(state);
|
|
198
|
+
const targetIndex = yield* indexFor(key, graphState);
|
|
199
|
+
const dependencyEdgeIndexes =
|
|
200
|
+
graphState.graph.reverseAdjacency.get(targetIndex) ?? [];
|
|
201
|
+
const dependencies: ReadonlyArray<ResourceDependency> =
|
|
202
|
+
Arr.getSomes(
|
|
203
|
+
Arr.map(dependencyEdgeIndexes, (edgeIndex) =>
|
|
204
|
+
Option.flatMap(
|
|
205
|
+
Option.fromUndefinedOr(
|
|
206
|
+
graphState.graph.edges.get(edgeIndex),
|
|
207
|
+
),
|
|
208
|
+
(dependencyEdge) =>
|
|
209
|
+
Option.map(
|
|
210
|
+
Option.fromUndefinedOr(
|
|
211
|
+
graphState.graph.nodes.get(dependencyEdge.source),
|
|
212
|
+
),
|
|
213
|
+
(sourceNode) => ({
|
|
214
|
+
source: sourceNode.key,
|
|
215
|
+
target: key,
|
|
216
|
+
edge: dependencyEdge.data,
|
|
217
|
+
}),
|
|
218
|
+
),
|
|
219
|
+
),
|
|
220
|
+
),
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
return dependencies;
|
|
224
|
+
},
|
|
225
|
+
),
|
|
226
|
+
/**
|
|
227
|
+
* CLI and debugging surfaces render the declared graph with resource
|
|
228
|
+
* labels and property mappings so humans can inspect the plan topology
|
|
229
|
+
* without reading persisted stack state.
|
|
230
|
+
*/
|
|
231
|
+
get mermaid() {
|
|
232
|
+
return Ref.get(state).pipe(
|
|
233
|
+
Effect.map((graphState) =>
|
|
234
|
+
Graph.toMermaid(graphState.graph, {
|
|
235
|
+
edgeLabel: (edge) =>
|
|
236
|
+
`${edge.property} <- ${edge.sourceProperty}`,
|
|
237
|
+
nodeLabel: resourceModel.resourceLabel,
|
|
238
|
+
}),
|
|
239
|
+
),
|
|
240
|
+
);
|
|
241
|
+
},
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Prepare and plan paths read the graph as a stable value after
|
|
245
|
+
* application declarations have run.
|
|
246
|
+
*/
|
|
247
|
+
get snapshot() {
|
|
248
|
+
return Ref.get(state).pipe(
|
|
249
|
+
Effect.map((graphState) => graphState.graph),
|
|
250
|
+
);
|
|
251
|
+
},
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* CLI status surfaces use topological ids when they need declaration
|
|
255
|
+
* order without materializing provider payloads.
|
|
256
|
+
*/
|
|
257
|
+
get topologicalLogicalIds() {
|
|
258
|
+
return Ref.get(state).pipe(
|
|
259
|
+
Effect.map((graphState) =>
|
|
260
|
+
Arr.map(
|
|
261
|
+
Arr.fromIterable(Graph.values(Graph.topo(graphState.graph))),
|
|
262
|
+
(node) => node.key.logicalId,
|
|
263
|
+
),
|
|
264
|
+
),
|
|
265
|
+
);
|
|
266
|
+
},
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Graph-backed diagnostics can inspect a resource output by key while
|
|
270
|
+
* still validating that outputs are JSON object data.
|
|
271
|
+
*/
|
|
272
|
+
outputValue: Effect.fn("ResourceGraphStore.outputValue")(function* (
|
|
273
|
+
key: ResourceKey,
|
|
274
|
+
property: string,
|
|
275
|
+
) {
|
|
276
|
+
const graphState = yield* Ref.get(state);
|
|
277
|
+
const nodeIndex = yield* indexFor(key, graphState);
|
|
278
|
+
const node = yield* nodeAt(graphState, key, nodeIndex);
|
|
279
|
+
const output = yield* Schema.decodeUnknownEffect(
|
|
280
|
+
Schema.Record(Schema.String, Schema.Json),
|
|
281
|
+
)(node.outputs);
|
|
282
|
+
|
|
283
|
+
return output[property];
|
|
284
|
+
}),
|
|
285
|
+
};
|
|
286
|
+
}),
|
|
287
|
+
},
|
|
288
|
+
) {}
|