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.
Files changed (81) hide show
  1. package/LICENSE +19 -0
  2. package/README.md +45 -0
  3. package/bin/nomoss +13 -0
  4. package/docs/code-documentation.md +36 -0
  5. package/docs/effect-native-development.md +55 -0
  6. package/docs/engine-design.md +93 -0
  7. package/docs/linting.md +88 -0
  8. package/docs/releasing.md +13 -0
  9. package/docs/resource-command-policy-stage.md +71 -0
  10. package/docs/resource-graph-mvp.md +31 -0
  11. package/docs/resource-graph-testing-approach.md +11 -0
  12. package/docs/resource-lifecycle-tracker.md +93 -0
  13. package/docs/testing.md +86 -0
  14. package/examples/upload-events/README.md +41 -0
  15. package/media/nomoss.gif +0 -0
  16. package/package.json +64 -0
  17. package/src/cli.ts +18 -0
  18. package/src/cliCommand.ts +186 -0
  19. package/src/cliRuntimeLayer.ts +49 -0
  20. package/src/core/index.ts +17 -0
  21. package/src/core/lifecycle.ts +127 -0
  22. package/src/core/model.ts +229 -0
  23. package/src/core/physicalNameStore.ts +226 -0
  24. package/src/core/planner.ts +645 -0
  25. package/src/core/resourceCommandPolicy.ts +79 -0
  26. package/src/core/resourceGraphBuilder.ts +167 -0
  27. package/src/core/resourceGraphStore.ts +288 -0
  28. package/src/core/resourceOutputResolver.ts +185 -0
  29. package/src/core/resourcePolicy.ts +77 -0
  30. package/src/core/resourceStackDefinition.ts +17 -0
  31. package/src/core/resourceStackLifecycle.ts +456 -0
  32. package/src/core/resourceStackOperations.ts +129 -0
  33. package/src/core/runtimeLayer.ts +73 -0
  34. package/src/core/stackWorkflowRenderer.ts +239 -0
  35. package/src/core/stateSecretService.ts +553 -0
  36. package/src/core/stateStore.ts +652 -0
  37. package/src/core/tracing.ts +26 -0
  38. package/src/index.ts +2 -0
  39. package/src/providers/aws/awsApply.ts +132 -0
  40. package/src/providers/aws/awsBucket.ts +329 -0
  41. package/src/providers/aws/awsBucketNotification.ts +351 -0
  42. package/src/providers/aws/awsBucketNotificationResourcePolicy.ts +251 -0
  43. package/src/providers/aws/awsBucketResourcePolicy.ts +198 -0
  44. package/src/providers/aws/awsProviderLayer.ts +274 -0
  45. package/src/providers/aws/awsQueue.ts +346 -0
  46. package/src/providers/aws/awsQueuePolicy.ts +419 -0
  47. package/src/providers/aws/awsQueuePolicyResourcePolicy.ts +215 -0
  48. package/src/providers/aws/awsQueueResourcePolicy.ts +270 -0
  49. package/src/providers/aws/awsReconciliation.ts +92 -0
  50. package/src/providers/aws/awsRefresh.ts +50 -0
  51. package/src/providers/aws/awsResourceLifecycle.ts +118 -0
  52. package/src/providers/aws/awsResourcePolicy.ts +83 -0
  53. package/src/providers/aws/awsResources.ts +274 -0
  54. package/src/providers/aws/awsRuntimeLayer.ts +21 -0
  55. package/src/providers/aws/awsSqsTransport.ts +33 -0
  56. package/src/providers/aws/awsStackLifecycle.ts +272 -0
  57. package/src/providers/aws/awsTagging.ts +186 -0
  58. package/src/providers/aws/constants.ts +3 -0
  59. package/src/providers/aws/index.ts +22 -0
  60. package/src/providers/aws/sampleStack.ts +65 -0
  61. package/src/providers/aws/stackWorkflow.ts +443 -0
  62. package/src/providers/index.ts +5 -0
  63. package/src/providers/provider.ts +5 -0
  64. package/src/providers/providerRuntimeLayer.ts +121 -0
  65. package/src/providers/resourceCommandPolicyLayer.ts +240 -0
  66. package/src/providers/stripe/index.ts +15 -0
  67. package/src/providers/stripe/stripeAccount.ts +139 -0
  68. package/src/providers/stripe/stripeBillingConfigurationExport.ts +180 -0
  69. package/src/providers/stripe/stripeBillingConfigurationExportResourcePolicy.ts +178 -0
  70. package/src/providers/stripe/stripeBillingPortalConfiguration.ts +153 -0
  71. package/src/providers/stripe/stripeBillingPortalConfigurationResourcePolicy.ts +177 -0
  72. package/src/providers/stripe/stripeCustomer.ts +148 -0
  73. package/src/providers/stripe/stripeCustomerResourcePolicy.ts +160 -0
  74. package/src/providers/stripe/stripePrice.ts +218 -0
  75. package/src/providers/stripe/stripePriceResourcePolicy.ts +151 -0
  76. package/src/providers/stripe/stripeProduct.ts +171 -0
  77. package/src/providers/stripe/stripeProductResourcePolicy.ts +161 -0
  78. package/src/providers/stripe/stripeResources.ts +454 -0
  79. package/src/providers/stripe/stripeRuntimeLayer.ts +131 -0
  80. package/src/providers/stripe/stripeWebhookEndpoint.ts +293 -0
  81. package/src/providers/stripe/stripeWebhookEndpointResourcePolicy.ts +198 -0
@@ -0,0 +1,229 @@
1
+ import { Context, Data, Effect, Equal, Option, Schema } from "effect";
2
+
3
+ import { ProviderIdSchema } from "../providers/provider.js";
4
+
5
+ export const ResourceKeySchema = Schema.Struct({
6
+ logicalId: Schema.NonEmptyString,
7
+ });
8
+
9
+ export type ResourceKey = Schema.Schema.Type<typeof ResourceKeySchema>;
10
+
11
+ export const DependencyEdgeSchema = Schema.Struct({
12
+ kind: Schema.Literal("property"),
13
+ property: Schema.NonEmptyString,
14
+ sourceProperty: Schema.NonEmptyString,
15
+ });
16
+
17
+ export type DependencyEdge = Schema.Schema.Type<typeof DependencyEdgeSchema>;
18
+
19
+ export const ResourceOutputRefSchema = Schema.TaggedStruct(
20
+ "ResourceOutputRef",
21
+ {
22
+ source: ResourceKeySchema,
23
+ property: Schema.NonEmptyString,
24
+ },
25
+ );
26
+
27
+ export type ResourceOutputRef = Schema.Schema.Type<
28
+ typeof ResourceOutputRefSchema
29
+ >;
30
+
31
+ /**
32
+ * Provider resource declarations attach this metadata to their props schema so
33
+ * `ResourceModel.nodeFromResource` can persist the provider command identity
34
+ * with each `ResourceNode`. Lifecycle planning selects that command from the
35
+ * persisted node, and `ResourceStateStore` uses named secret outputs to keep
36
+ * provider-only values out of the durable state file.
37
+ */
38
+ export const ResourceSchemaAnnotationSchema = Schema.Struct({
39
+ provider: ProviderIdSchema,
40
+ service: Schema.NonEmptyString,
41
+ resource: Schema.NonEmptyString,
42
+ operation: Schema.Literals(["create", "read", "update", "delete"]),
43
+ stateSecretOutputKeys: Schema.Array(Schema.NonEmptyString),
44
+ });
45
+
46
+ export type ResourceSchemaAnnotation = Schema.Schema.Type<
47
+ typeof ResourceSchemaAnnotationSchema
48
+ >;
49
+
50
+ export const ResourceSchemaAnnotationId = Symbol.for(
51
+ "@nomoss/resourceSchemaAnnotation",
52
+ );
53
+
54
+ declare module "effect/Schema" {
55
+ namespace Annotations {
56
+ interface Annotations {
57
+ readonly [ResourceSchemaAnnotationId]?: ResourceSchemaAnnotation;
58
+ }
59
+ }
60
+ }
61
+
62
+ export const ResourceNodeSchema = Schema.Struct({
63
+ key: ResourceKeySchema,
64
+ schema: ResourceSchemaAnnotationSchema,
65
+ props: Schema.Json,
66
+ outputs: Schema.Json,
67
+ });
68
+
69
+ export type ResourceNode = Schema.Schema.Type<typeof ResourceNodeSchema>;
70
+
71
+ export type PlanAction = Data.TaggedEnum<{
72
+ Create: {
73
+ readonly node: ResourceNode;
74
+ };
75
+ Update: {
76
+ readonly node: ResourceNode;
77
+ readonly current: ResourceNode;
78
+ };
79
+ Delete: {
80
+ readonly node: ResourceNode;
81
+ };
82
+ Destroy: {
83
+ readonly node: ResourceNode;
84
+ };
85
+ }>;
86
+
87
+ export const PlanAction = Data.taggedEnum<PlanAction>();
88
+
89
+ export type ResourcePlan = {
90
+ readonly createOrUpdate: ReadonlyArray<ReadonlyArray<PlanAction>>;
91
+ readonly delete: ReadonlyArray<ReadonlyArray<PlanAction>>;
92
+ readonly destroy: ReadonlyArray<ReadonlyArray<PlanAction>>;
93
+ };
94
+
95
+ export class ResourceSchemaAnnotationMissing extends Data.TaggedError(
96
+ "ResourceSchemaAnnotationMissing",
97
+ )<{
98
+ readonly logicalId: string;
99
+ }> {}
100
+
101
+ export const keyString = (key: ResourceKey) => key.logicalId;
102
+
103
+ export const resourceSchemaString = (schema: ResourceSchemaAnnotation) =>
104
+ `${schema.provider}:${schema.service}:${schema.resource}:${schema.operation}`;
105
+
106
+ export const annotateResourceSchema = <
107
+ Resource,
108
+ ResourceSchema extends Schema.Schema<Resource>,
109
+ >(
110
+ schema: ResourceSchema,
111
+ annotation: ResourceSchemaAnnotation,
112
+ ) =>
113
+ schema.annotate({
114
+ [ResourceSchemaAnnotationId]:
115
+ ResourceSchemaAnnotationSchema.make(annotation),
116
+ });
117
+
118
+ export const readResourceSchemaAnnotation = <Resource>(
119
+ schema: Schema.Schema<Resource>,
120
+ ) =>
121
+ Option.fromUndefinedOr(
122
+ Schema.resolveAnnotations(schema)?.[ResourceSchemaAnnotationId],
123
+ ).pipe(
124
+ Option.flatMap((annotation) =>
125
+ ResourceSchemaAnnotationSchema.makeOption(annotation),
126
+ ),
127
+ );
128
+
129
+ export const resourceOutputRef = (
130
+ source: ResourceKey,
131
+ property: string,
132
+ ): ResourceOutputRef => {
133
+ const outputRef = ResourceOutputRefSchema.make({
134
+ _tag: "ResourceOutputRef",
135
+ source,
136
+ property,
137
+ });
138
+
139
+ return outputRef;
140
+ };
141
+
142
+ /**
143
+ * Resource constructors and policies pass provider data through this service
144
+ * so graph nodes, JSON payloads, and display metadata share one
145
+ * schema-backed contract.
146
+ */
147
+ export class ResourceModel extends Context.Service<ResourceModel>()(
148
+ "nomoss/core/model/ResourceModel",
149
+ {
150
+ make: Effect.succeed({
151
+ nodeFromResource: <
152
+ Props,
153
+ Outputs,
154
+ PropsSchema extends Schema.Schema<Props>,
155
+ OutputsSchema extends Schema.Schema<Outputs>,
156
+ >(input: {
157
+ readonly key: ResourceKey;
158
+ readonly propsSchema: PropsSchema;
159
+ readonly outputsSchema: OutputsSchema;
160
+ readonly props: NoInfer<Props>;
161
+ readonly outputs: NoInfer<Outputs>;
162
+ }) =>
163
+ Effect.gen(function* () {
164
+ const schema = yield* readResourceSchemaAnnotation(
165
+ input.propsSchema,
166
+ ).pipe(
167
+ Option.match({
168
+ onNone: () =>
169
+ Effect.fail(
170
+ new ResourceSchemaAnnotationMissing({
171
+ logicalId: input.key.logicalId,
172
+ }),
173
+ ),
174
+ onSome: Effect.succeed,
175
+ }),
176
+ );
177
+ const props = yield* input.propsSchema.makeEffect(input.props);
178
+ const outputs = yield* input.outputsSchema.makeEffect(input.outputs);
179
+ const resourceProps = yield* Schema.decodeUnknownEffect(Schema.Json)(
180
+ props,
181
+ );
182
+ const resourceOutputs = yield* Schema.decodeUnknownEffect(
183
+ Schema.Json,
184
+ )(outputs);
185
+ const resourceNode = yield* ResourceNodeSchema.makeEffect({
186
+ key: input.key,
187
+ schema,
188
+ props: resourceProps,
189
+ outputs: resourceOutputs,
190
+ });
191
+
192
+ return resourceNode;
193
+ }),
194
+
195
+ decodeProps: <Props>(node: ResourceNode, schema: Schema.Schema<Props>) =>
196
+ schema.makeEffect(node.props),
197
+
198
+ decodeOutputs: <Outputs>(
199
+ node: ResourceNode,
200
+ schema: Schema.Schema<Outputs>,
201
+ ) => schema.makeEffect(node.outputs),
202
+
203
+ decodeJson: <Resource>(
204
+ schema: Schema.Schema<Resource>,
205
+ encoded: Schema.Json,
206
+ ) => schema.makeEffect(encoded),
207
+
208
+ encodeJson: <Resource>(
209
+ schema: Schema.Schema<Resource>,
210
+ value: NoInfer<Resource>,
211
+ ) =>
212
+ Effect.gen(function* () {
213
+ const checked = yield* schema.makeEffect(value);
214
+ const json = yield* Schema.Json.makeEffect(checked);
215
+
216
+ return json;
217
+ }),
218
+
219
+ propsEqual: (left: ResourceNode, right: ResourceNode) =>
220
+ Equal.equals(left.props, right.props),
221
+
222
+ resourceLabel: (node: ResourceNode) =>
223
+ `${node.schema.provider}:${node.schema.service}:${node.schema.resource}/${keyString(node.key)}`,
224
+
225
+ actionString: (action: PlanAction) =>
226
+ `${action._tag} ${action.node.schema.provider}:${action.node.schema.service}:${action.node.schema.resource}/${keyString(action.node.key)}`,
227
+ }),
228
+ },
229
+ ) {}
@@ -0,0 +1,226 @@
1
+ import { randomUUID } from "node:crypto";
2
+
3
+ import {
4
+ Array as Arr,
5
+ Context,
6
+ Effect,
7
+ FileSystem,
8
+ Match,
9
+ Option,
10
+ Record,
11
+ Schema,
12
+ String as Str,
13
+ } from "effect";
14
+
15
+ const PhysicalNameFileSchema = Schema.Struct({
16
+ schemaVersion: Schema.Literal(1),
17
+ names: Schema.Record(Schema.String, Schema.String),
18
+ });
19
+
20
+ type PhysicalNameFile = Schema.Schema.Type<typeof PhysicalNameFileSchema>;
21
+
22
+ const PhysicalNameJsonSchema = Schema.fromJsonString(PhysicalNameFileSchema);
23
+
24
+ type SanitizedNameState = {
25
+ readonly pendingSeparator: boolean;
26
+ readonly text: string;
27
+ };
28
+
29
+ /**
30
+ * Generated provider names must remain stable across local runs when callers
31
+ * omit explicit names. Destroy clears those mappings so recreated stacks do not
32
+ * reuse stale names during provider cooldown windows.
33
+ */
34
+ export class PhysicalNameStore extends Context.Service<PhysicalNameStore>()(
35
+ "nomoss/core/physicalNameStore",
36
+ {
37
+ make: Effect.gen(function* () {
38
+ const fs = yield* FileSystem.FileSystem;
39
+ const emptyState = PhysicalNameFileSchema.make({
40
+ schemaVersion: 1,
41
+ names: {},
42
+ });
43
+ const appendSanitizedNameCharacter = (
44
+ nameState: SanitizedNameState,
45
+ nameCharacter: string,
46
+ ): SanitizedNameState => ({
47
+ pendingSeparator: false,
48
+ text: `${nameState.text}${Match.value(nameState.pendingSeparator).pipe(
49
+ Match.when(true, () => "-"),
50
+ Match.orElse(() => ""),
51
+ )}${nameCharacter}`,
52
+ });
53
+ const readState = Effect.fn("PhysicalNameStore.readState")(function* () {
54
+ return yield* fs
55
+ .readFileString("./.nomoss/physical-names.json")
56
+ .pipe(
57
+ Effect.flatMap(Schema.decodeUnknownEffect(PhysicalNameJsonSchema)),
58
+ Effect.when(fs.exists("./.nomoss/physical-names.json")),
59
+ Effect.map(Option.getOrElse(() => emptyState)),
60
+ );
61
+ });
62
+ const writeState = Effect.fn("PhysicalNameStore.writeState")(function* (
63
+ state: PhysicalNameFile,
64
+ ) {
65
+ const encoded = yield* Schema.encodeEffect(PhysicalNameJsonSchema)(
66
+ state,
67
+ );
68
+
69
+ yield* fs.makeDirectory("./.nomoss", { recursive: true });
70
+ yield* fs.writeFileString("./.nomoss/physical-names.json", encoded);
71
+ });
72
+ const createMissingBucketName = Effect.fn(
73
+ "PhysicalNameStore.createMissingBucketName",
74
+ )(function* (state: PhysicalNameFile, logicalId: string) {
75
+ const uuid = yield* Effect.sync(randomUUID);
76
+ const suffix = Str.takeLeft(
77
+ Arr.join(
78
+ Arr.filter(Str.split(uuid, ""), (character) => character !== "-"),
79
+ "",
80
+ ),
81
+ 8,
82
+ );
83
+ const sanitized = Arr.reduce(
84
+ Str.split(logicalId, ""),
85
+ {
86
+ pendingSeparator: Boolean(false),
87
+ text: String(Str.empty),
88
+ },
89
+ (nameState, character) =>
90
+ Match.value(Str.toLowerCase(character)).pipe(
91
+ Match.when(
92
+ (candidate) =>
93
+ Str.includes(candidate)(
94
+ "abcdefghijklmnopqrstuvwxyz0123456789",
95
+ ),
96
+ (candidate) => Option.some<string>(candidate),
97
+ ),
98
+ Match.when(
99
+ (candidate) => Str.includes(candidate)("-"),
100
+ (candidate) => Option.some<string>(candidate),
101
+ ),
102
+ Match.orElse(() => Option.none<string>()),
103
+ Option.match({
104
+ onNone: () => ({
105
+ pendingSeparator: Str.isNonEmpty(nameState.text),
106
+ text: nameState.text,
107
+ }),
108
+ onSome: (nameCharacter) =>
109
+ appendSanitizedNameCharacter(nameState, nameCharacter),
110
+ }),
111
+ ),
112
+ ).text;
113
+ const name = `nomoss-${sanitized}-${suffix}`;
114
+ const nextState: PhysicalNameFile = {
115
+ schemaVersion: 1,
116
+ names: Record.set(state.names, logicalId, name),
117
+ };
118
+
119
+ yield* writeState(nextState);
120
+
121
+ return name;
122
+ });
123
+ const createMissingQueueName = Effect.fn(
124
+ "PhysicalNameStore.createMissingQueueName",
125
+ )(function* (state: PhysicalNameFile, logicalId: string) {
126
+ const uuid = yield* Effect.sync(randomUUID);
127
+ const suffix = Str.takeLeft(
128
+ Arr.join(
129
+ Arr.filter(Str.split(uuid, ""), (character) => character !== "-"),
130
+ "",
131
+ ),
132
+ 8,
133
+ );
134
+ const sanitized = Arr.reduce(
135
+ Str.split(logicalId, ""),
136
+ {
137
+ pendingSeparator: Boolean(false),
138
+ text: String(Str.empty),
139
+ },
140
+ (nameState, character) =>
141
+ Match.value(Str.toLowerCase(character)).pipe(
142
+ Match.when(
143
+ (candidate) =>
144
+ Str.includes(candidate)(
145
+ "abcdefghijklmnopqrstuvwxyz0123456789",
146
+ ),
147
+ (candidate) => Option.some<string>(candidate),
148
+ ),
149
+ Match.when(
150
+ (candidate) => Str.includes(candidate)("_-"),
151
+ (candidate) => Option.some<string>(candidate),
152
+ ),
153
+ Match.orElse(() => Option.none<string>()),
154
+ Option.match({
155
+ onNone: () => ({
156
+ pendingSeparator: Str.isNonEmpty(nameState.text),
157
+ text: nameState.text,
158
+ }),
159
+ onSome: (nameCharacter) =>
160
+ appendSanitizedNameCharacter(nameState, nameCharacter),
161
+ }),
162
+ ),
163
+ ).text;
164
+ const name = `nomoss-${sanitized}-${suffix}`;
165
+ const nextState: PhysicalNameFile = {
166
+ schemaVersion: 1,
167
+ names: Record.set(state.names, logicalId, name),
168
+ };
169
+
170
+ yield* writeState(nextState);
171
+
172
+ return name;
173
+ });
174
+ const bucketNameFor = Effect.fn("PhysicalNameStore.bucketNameFor")(
175
+ function* (logicalId: string) {
176
+ const state = yield* readState();
177
+ const existing = Option.fromUndefinedOr(state.names[logicalId]);
178
+
179
+ return yield* Match.value(existing).pipe(
180
+ Match.when({ _tag: "Some" }, ({ value }) => Effect.succeed(value)),
181
+ Match.when({ _tag: "None" }, () =>
182
+ createMissingBucketName(state, logicalId),
183
+ ),
184
+ Match.exhaustive,
185
+ );
186
+ },
187
+ );
188
+ const queueNameFor = Effect.fn("PhysicalNameStore.queueNameFor")(
189
+ function* (logicalId: string) {
190
+ const state = yield* readState();
191
+ const existing = Option.fromUndefinedOr(state.names[logicalId]);
192
+
193
+ return yield* Match.value(existing).pipe(
194
+ Match.when({ _tag: "Some" }, ({ value }) => Effect.succeed(value)),
195
+ Match.when({ _tag: "None" }, () =>
196
+ createMissingQueueName(state, logicalId),
197
+ ),
198
+ Match.exhaustive,
199
+ );
200
+ },
201
+ );
202
+
203
+ return {
204
+ bucketNameFor,
205
+ queueNameFor,
206
+
207
+ deleteNames: Effect.fn("PhysicalNameStore.deleteNames")(function* (
208
+ logicalIds: ReadonlyArray<string>,
209
+ ) {
210
+ const state = yield* readState();
211
+ const names = Arr.reduce(
212
+ logicalIds,
213
+ state.names,
214
+ (remaining, logicalId) => Record.remove(remaining, logicalId),
215
+ );
216
+ const nextState: PhysicalNameFile = {
217
+ schemaVersion: 1,
218
+ names,
219
+ };
220
+
221
+ yield* writeState(nextState);
222
+ }),
223
+ };
224
+ }),
225
+ },
226
+ ) {}