@geekmidas/cloud 10.0.0-alpha.18 → 10.0.0-alpha.180

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 (35) hide show
  1. package/README.md +26 -6
  2. package/package.json +9 -8
  3. package/src/sst/__tests__/api.spec.ts +0 -46
  4. package/src/sst/__tests__/bootstrap.spec.ts +15 -0
  5. package/src/sst/__tests__/encryption.spec.ts +90 -0
  6. package/src/sst/__tests__/fromManifest.inbox.spec.ts +157 -0
  7. package/src/sst/__tests__/fromManifest.integration.spec.ts +87 -3
  8. package/src/sst/__tests__/fromManifest.secret.spec.ts +79 -0
  9. package/src/sst/__tests__/fromManifest.spec.ts +412 -18
  10. package/src/sst/__tests__/function.spec.ts +0 -71
  11. package/src/sst/__tests__/hostLabels.spec.ts +74 -0
  12. package/src/sst/__tests__/surfaces.spec.ts +68 -5
  13. package/src/sst/__tests__/websocket.spec.ts +207 -0
  14. package/src/sst/__tests__/wildcardSite.spec.ts +195 -0
  15. package/src/sst/__type-tests__/overrides.type-test.ts +152 -0
  16. package/src/sst/aws/Api.ts +0 -43
  17. package/src/sst/aws/Credential.ts +42 -9
  18. package/src/sst/aws/Cron.ts +5 -45
  19. package/src/sst/aws/DatabaseBootstrap.ts +6 -0
  20. package/src/sst/aws/Encryption.ts +91 -0
  21. package/src/sst/aws/ExternalApi.ts +58 -0
  22. package/src/sst/aws/Function.ts +9 -38
  23. package/src/sst/aws/Inbox.ts +141 -0
  24. package/src/sst/aws/ObjectStorage.ts +3 -3
  25. package/src/sst/aws/Queue.ts +34 -1
  26. package/src/sst/aws/RestApiSurface.ts +36 -14
  27. package/src/sst/aws/Secret.ts +6 -4
  28. package/src/sst/aws/StaticSite.ts +44 -1
  29. package/src/sst/aws/WebSocketApiSurface.ts +160 -0
  30. package/src/sst/aws/bootstrap/handler.ts +12 -1
  31. package/src/sst/errors.ts +37 -0
  32. package/src/sst/fromManifest.ts +624 -71
  33. package/src/sst/index.ts +21 -1
  34. package/src/sst/overrides.ts +149 -0
  35. package/src/sst/__type-tests__/manifest.type-test.ts +0 -77
package/src/sst/index.ts CHANGED
@@ -34,8 +34,15 @@ export {
34
34
  } from './aws/DatabaseBootstrap';
35
35
  export { DatabaseReader, DatabaseSchema } from './aws/DerivedDatabase';
36
36
  export { Email, EmailNeedsUrl, type EmailProps } from './aws/Email';
37
+ export { Encryption, type EncryptionProps } from './aws/Encryption';
37
38
  export { FileServer, type FileServerProps } from './aws/FileServer';
38
39
  export { Function, type FunctionProps } from './aws/Function';
40
+ export {
41
+ Inbox,
42
+ InboxNotProvisioned,
43
+ type InboxProps,
44
+ InboxTopic,
45
+ } from './aws/Inbox';
39
46
  export {
40
47
  ObjectStorage,
41
48
  type ObjectStorageProps,
@@ -55,13 +62,21 @@ export {
55
62
  } from './aws/ses';
56
63
  export { Topic, type TopicProps } from './aws/Topic';
57
64
  export {
65
+ regionOfEndpoint,
66
+ routeSelectionExpression,
67
+ WebSocketApiSurface,
68
+ type WebSocketApiSurfaceProps,
69
+ type WebSocketSurfaceRoute,
70
+ } from './aws/WebSocketApiSurface';
71
+ export {
72
+ HostLabelNeedsCustomDomain,
58
73
  ProvidesMismatch,
59
74
  UnknownDeclarationKind,
60
75
  UnresolvedDependency,
76
+ WildcardSiteNeedsDomain,
61
77
  } from './errors';
62
78
  export {
63
79
  assertProvides,
64
- type ComponentOverrides,
65
80
  describeRoutes,
66
81
  fromManifest,
67
82
  isServed,
@@ -75,4 +90,9 @@ export {
75
90
  } from './fromManifest';
76
91
  export { type GkmLinkable, ResourceType } from './Linkable';
77
92
  export { kebab, prefixedName, regionOfArn } from './naming';
93
+ export type {
94
+ ManifestBackends,
95
+ ManifestOverrides,
96
+ OverrideFor,
97
+ } from './overrides';
78
98
  export { Stack, type StackType } from './Stack';
@@ -0,0 +1,149 @@
1
+ /**
2
+ * What a deploy can say about each construct, inferred from the manifest.
3
+ *
4
+ * `fromManifest` used to take `Record<string, Record<string, unknown>>`, so a
5
+ * misspelt id, a prop the component never reads, and a missing VPC all passed
6
+ * the type checker — the first two silently, the last at synth, mid-deploy.
7
+ * The manifest is emitted `as const`, so every id's kind is known statically,
8
+ * and the kind decides what can be overridden:
9
+ *
10
+ * - only the manifest's own ids are keys;
11
+ * - each takes the props its kind's provisioner reads, minus those the
12
+ * declaration already decides (a site's `path`, a file server's `origin`);
13
+ * - what the synth refuses to guess is required — a database's `vpc`, mail's
14
+ * `from`, and, by backend, an ElastiCache `vpc` or a non-SES mail `url`;
15
+ * - a kind with nothing to override takes no key at all.
16
+ */
17
+
18
+ import type { ConstructManifest, DeclarationKind } from '@geekmidas/manifest';
19
+ import type { CacheProps } from './aws/Cache';
20
+ import type { CredentialProps } from './aws/Credential';
21
+ import type { DatabaseProps } from './aws/Database';
22
+ import type { EncryptionProps } from './aws/Encryption';
23
+ import type { ExternalApiProps } from './aws/ExternalApi';
24
+ import type { FileServerProps } from './aws/FileServer';
25
+ import type { InboxProps } from './aws/Inbox';
26
+ import type { ObjectStorageProps } from './aws/ObjectStorage';
27
+ import type { QueueProps } from './aws/Queue';
28
+ import type { SecretProps } from './aws/Secret';
29
+ import type { StaticSiteProps } from './aws/StaticSite';
30
+ import type { TopicProps } from './aws/Topic';
31
+
32
+ /** The backend choices that are config rather than declaration. */
33
+ export interface ManifestBackends {
34
+ cache?: 'upstash' | 'elasticache' | 'db';
35
+ email?: 'resend' | 'ses' | 'smtp';
36
+ /**
37
+ * The labels no tenant of a wildcard site may take: every app's own and
38
+ * the workspace's `protectedSubdomains`, as `gkm build` derived them.
39
+ */
40
+ protectedSubdomains?: readonly string[];
41
+ }
42
+
43
+ /** The backend a choice resolves to — the provisioner's default when unset. */
44
+ type CacheBackendOf<B extends ManifestBackends> =
45
+ B['cache'] extends NonNullable<ManifestBackends['cache']>
46
+ ? B['cache']
47
+ : 'upstash';
48
+ type EmailBackendOf<B extends ManifestBackends> =
49
+ B['email'] extends NonNullable<ManifestBackends['email']>
50
+ ? B['email']
51
+ : 'ses';
52
+
53
+ type CacheOverride<Backend> = Backend extends 'elasticache'
54
+ ? { vpc: NonNullable<CacheProps['vpc']> }
55
+ : Backend extends 'upstash'
56
+ ? { url?: CacheProps['url']; region?: string }
57
+ : never;
58
+
59
+ type EmailOverride<Backend> = {
60
+ /** Every provider rejects an unverified sender, so there is no default. */
61
+ from: $util.Input<string>;
62
+ region?: $util.Input<string>;
63
+ } & (Backend extends 'ses'
64
+ ? { url?: $util.Input<string> }
65
+ : // Resend and a relay are accounts somebody created: their URL is theirs.
66
+ { url: $util.Input<string> });
67
+
68
+ /**
69
+ * What one declaration takes, by its kind and the backends; `never` for a kind
70
+ * with nothing to override, which drops its id from the keys.
71
+ */
72
+ export type OverrideFor<D, B extends ManifestBackends = {}> = D extends {
73
+ kind: infer K extends DeclarationKind;
74
+ }
75
+ ? K extends 'objects'
76
+ ? Partial<ObjectStorageProps>
77
+ : K extends 'file-server'
78
+ ? Partial<Omit<FileServerProps, 'origin'>>
79
+ : K extends 'site'
80
+ ? Partial<
81
+ Omit<
82
+ StaticSiteProps,
83
+ 'path' | 'variant' | 'environment' | 'tenants'
84
+ >
85
+ >
86
+ : K extends 'queue'
87
+ ? Partial<Omit<QueueProps, 'fifo'>>
88
+ : K extends 'topic'
89
+ ? Partial<TopicProps>
90
+ : K extends 'database'
91
+ ? Omit<DatabaseProps, 'schema' | 'version'>
92
+ : K extends 'cache'
93
+ ? // In a database: same address, one more table, nothing to say.
94
+ D extends { of: string }
95
+ ? never
96
+ : CacheOverride<CacheBackendOf<B>>
97
+ : K extends 'email'
98
+ ? EmailOverride<EmailBackendOf<B>>
99
+ : K extends 'rest-api'
100
+ ? Partial<sst.aws.ApiGatewayV2Args>
101
+ : K extends 'websocket-api'
102
+ ? Partial<sst.aws.ApiGatewayWebSocketArgs>
103
+ : K extends 'secret'
104
+ ? SecretProps
105
+ : K extends 'credential'
106
+ ? CredentialProps
107
+ : K extends 'encryption'
108
+ ? Partial<EncryptionProps>
109
+ : K extends 'external-api'
110
+ ? Omit<ExternalApiProps, 'url'>
111
+ : K extends 'inbox'
112
+ ? // Its provider's values; the deploy's env otherwise.
113
+ Partial<Omit<InboxProps, 'topicId'>>
114
+ : // Derived databases, compute, mobile apps, OIDC.
115
+ never
116
+ : never;
117
+
118
+ /** Whether `{}` satisfies an override — whether the id can be left out. */
119
+ type IsOptional<T> = {} extends T ? true : false;
120
+
121
+ type Overridable<M, B extends ManifestBackends> = {
122
+ [Id in keyof M]: [OverrideFor<M[Id], B>] extends [never] ? never : Id;
123
+ }[keyof M];
124
+
125
+ type RequiredIds<M, B extends ManifestBackends> = {
126
+ [Id in Overridable<M, B>]: IsOptional<OverrideFor<M[Id], B>> extends true
127
+ ? never
128
+ : Id;
129
+ }[Overridable<M, B>];
130
+
131
+ /**
132
+ * The overrides a manifest accepts, keyed by its own construct ids.
133
+ *
134
+ * A manifest typed only as `ConstructManifest` — ids unknown — falls back to
135
+ * the untyped record, and the provisioners' synth-time checks still apply.
136
+ */
137
+ export type ManifestOverrides<
138
+ M extends ConstructManifest,
139
+ B extends ManifestBackends = {},
140
+ > = string extends keyof M
141
+ ? Record<string, Record<string, unknown>>
142
+ : {
143
+ [Id in RequiredIds<M, B>]: OverrideFor<M[Id], B>;
144
+ } & {
145
+ [Id in Exclude<Overridable<M, B>, RequiredIds<M, B>>]?: OverrideFor<
146
+ M[Id],
147
+ B
148
+ >;
149
+ };
@@ -1,77 +0,0 @@
1
- // Type-level checks that the `fromManifest` integrators accept the unified
2
- // `gkm build` manifest shape (`export const manifest = { … } as const`) — both
3
- // the flat and the partitioned `ManifestField` forms. Checked by `ts:check:sst`.
4
-
5
- import type { Manifest, ManifestField, RouteInfo } from '@geekmidas/manifest';
6
- import { App } from '../App';
7
- import { Api } from '../aws/Api';
8
- import { Cron } from '../aws/Cron';
9
- import { Function } from '../aws/Function';
10
- import { type GkmLinkable, ResourceType } from '../Linkable';
11
-
12
- const stack = new App({
13
- name: 'a',
14
- stage: 'dev',
15
- domain: 'example.com',
16
- hostedZoneId: 'Z',
17
- region: 'us-east-1',
18
- }).stack('api');
19
-
20
- const db: GkmLinkable = { _id: 'db', _type: ResourceType.Postgres };
21
-
22
- // Mirrors a generated `manifest/aws.ts` — one object, `as const`.
23
- const manifest = {
24
- routes: [
25
- {
26
- path: '/users/{id}',
27
- method: 'GET',
28
- handler: 'users.handler',
29
- authorizer: 'none',
30
- environment: ['DB_HOST'],
31
- timeout: 30,
32
- memorySize: 1024,
33
- },
34
- ],
35
- functions: [
36
- { name: 'worker', handler: 'worker.handler', environment: ['DB_URL'] },
37
- ],
38
- crons: [
39
- { name: 'nightly', handler: 'nightly.handler', schedule: 'rate(1 day)' },
40
- ],
41
- } as const satisfies Manifest;
42
-
43
- // Each integrator takes the manifest *field*.
44
- export const api = Api.fromManifest(stack, 'Api', manifest.routes, {
45
- links: [db],
46
- authorizers: { jwt: { issuer: 'https://i', audiences: ['a'] } },
47
- });
48
- export const workers = Function.fromManifest(stack, manifest.functions, {
49
- links: [db],
50
- });
51
- export const crons = Cron.fromManifest(stack, manifest.crons, { links: [db] });
52
-
53
- // The partitioned `ManifestField` form is also accepted.
54
- const partitionedRoutes = {
55
- admin: [
56
- {
57
- path: '/admin',
58
- method: 'GET',
59
- handler: 'admin.handler',
60
- authorizer: 'iam',
61
- },
62
- ],
63
- default: [
64
- {
65
- path: '/health',
66
- method: 'GET',
67
- handler: 'health.handler',
68
- authorizer: 'none',
69
- },
70
- ],
71
- } satisfies ManifestField<RouteInfo>;
72
- export const partitionedApi = Api.fromManifest(
73
- stack,
74
- 'PartApi',
75
- partitionedRoutes,
76
- { links: [db] },
77
- );