alchemy 0.1.18 → 0.2.0
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/lib/alchemy.d.ts +67 -0
- package/lib/alchemy.js +40 -0
- package/lib/apply.d.ts +3 -20
- package/lib/apply.js +86 -82
- package/lib/aws/account-id.d.ts +0 -1
- package/lib/aws/account-id.js +0 -1
- package/lib/aws/bucket.d.ts +4 -7
- package/lib/aws/bucket.js +8 -12
- package/lib/aws/function.d.ts +4 -7
- package/lib/aws/function.js +9 -30
- package/lib/aws/index.d.ts +1 -1
- package/lib/aws/index.js +1 -1
- package/lib/aws/oidc/github-oidc-provider.d.ts +2 -6
- package/lib/aws/oidc/github-oidc-provider.js +10 -15
- package/lib/aws/oidc/index.d.ts +0 -1
- package/lib/aws/oidc/index.js +0 -1
- package/lib/aws/oidc/oidc-provider.d.ts +4 -6
- package/lib/aws/oidc/oidc-provider.js +9 -11
- package/lib/aws/policy-attachment.d.ts +9 -0
- package/lib/aws/policy-attachment.js +20 -0
- package/lib/aws/policy.d.ts +4 -16
- package/lib/aws/policy.js +9 -40
- package/lib/aws/queue.d.ts +4 -34
- package/lib/aws/queue.js +10 -20
- package/lib/aws/role.d.ts +4 -7
- package/lib/aws/role.js +17 -26
- package/lib/aws/ses.d.ts +4 -10
- package/lib/aws/ses.js +118 -131
- package/lib/aws/table.d.ts +4 -7
- package/lib/aws/table.js +8 -11
- package/lib/cloudflare/api.d.ts +0 -1
- package/lib/cloudflare/api.js +0 -1
- package/lib/cloudflare/asset-manifest.d.ts +0 -1
- package/lib/cloudflare/asset-manifest.js +0 -1
- package/lib/cloudflare/auth.d.ts +0 -1
- package/lib/cloudflare/auth.js +0 -1
- package/lib/cloudflare/bindings.d.ts +1 -1
- package/lib/cloudflare/bindings.js +3 -2
- package/lib/cloudflare/bound.d.ts +0 -1
- package/lib/cloudflare/bound.js +0 -1
- package/lib/cloudflare/bucket.d.ts +7 -15
- package/lib/cloudflare/bucket.js +12 -19
- package/lib/cloudflare/durable-object-namespace.d.ts +0 -3
- package/lib/cloudflare/durable-object-namespace.js +0 -4
- package/lib/cloudflare/generate-asset-manifest.d.ts +0 -1
- package/lib/cloudflare/generate-asset-manifest.js +1 -2
- package/lib/cloudflare/index.d.ts +0 -1
- package/lib/cloudflare/index.js +0 -1
- package/lib/cloudflare/kv-namespace.d.ts +6 -9
- package/lib/cloudflare/kv-namespace.js +16 -20
- package/lib/cloudflare/state.d.ts +0 -1
- package/lib/cloudflare/state.js +0 -1
- package/lib/cloudflare/static-site-router.d.ts +0 -1
- package/lib/cloudflare/static-site-router.js +0 -4
- package/lib/cloudflare/static-site.d.ts +5 -11
- package/lib/cloudflare/static-site.js +16 -28
- package/lib/cloudflare/types.d.ts +0 -1
- package/lib/cloudflare/types.js +0 -1
- package/lib/cloudflare/upload-asset-manifest.d.ts +0 -1
- package/lib/cloudflare/upload-asset-manifest.js +0 -1
- package/lib/cloudflare/worker-metadata.d.ts +0 -1
- package/lib/cloudflare/worker-metadata.js +0 -1
- package/lib/cloudflare/worker-migration.d.ts +0 -1
- package/lib/cloudflare/worker-migration.js +0 -1
- package/lib/cloudflare/worker.d.ts +8 -14
- package/lib/cloudflare/worker.js +37 -49
- package/lib/context.d.ts +58 -0
- package/lib/context.js +36 -0
- package/lib/destroy.d.ts +10 -13
- package/lib/destroy.js +104 -43
- package/lib/{esbuild.d.ts → esbuild/bundle.d.ts} +4 -18
- package/lib/{esbuild.js → esbuild/bundle.js} +10 -24
- package/lib/esbuild/index.d.ts +1 -0
- package/lib/esbuild/index.js +1 -0
- package/lib/fs/file.d.ts +13 -0
- package/lib/fs/file.js +20 -0
- package/lib/fs/folder.d.ts +10 -0
- package/lib/fs/folder.js +16 -0
- package/lib/fs/index.d.ts +2 -0
- package/lib/fs/index.js +2 -0
- package/lib/github/client.d.ts +0 -1
- package/lib/github/client.js +0 -1
- package/lib/github/index.d.ts +0 -1
- package/lib/github/index.js +0 -1
- package/lib/github/secret.d.ts +4 -6
- package/lib/github/secret.js +10 -12
- package/lib/index.d.ts +6 -10
- package/lib/index.js +5 -9
- package/lib/resource.d.ts +34 -62
- package/lib/resource.js +29 -270
- package/lib/scope.d.ts +35 -14
- package/lib/scope.js +78 -23
- package/lib/secret.d.ts +2 -7
- package/lib/secret.js +7 -20
- package/lib/state.d.ts +14 -10
- package/lib/state.js +15 -14
- package/lib/stripe/index.d.ts +0 -1
- package/lib/stripe/index.js +0 -1
- package/lib/stripe/price.d.ts +4 -5
- package/lib/stripe/price.js +10 -20
- package/lib/stripe/product.d.ts +4 -5
- package/lib/stripe/product.js +10 -20
- package/lib/stripe/webhook.d.ts +4 -6
- package/lib/stripe/webhook.js +12 -25
- package/lib/test/bun.d.ts +19 -0
- package/lib/test/bun.js +55 -0
- package/lib/{utils → util}/content-type.d.ts +0 -1
- package/lib/{utils → util}/content-type.js +0 -1
- package/lib/{encrypt.d.ts → util/encrypt.d.ts} +0 -1
- package/lib/{encrypt.js → util/encrypt.js} +0 -1
- package/lib/{error.d.ts → util/ignore.d.ts} +0 -1
- package/lib/{error.js → util/ignore.js} +0 -1
- package/lib/{utils → util}/retry.d.ts +0 -1
- package/lib/{utils → util}/retry.js +0 -1
- package/lib/util/serde.d.ts +3 -0
- package/lib/{serde.js → util/serde.js} +19 -10
- package/lib/util/slugify.d.ts +1 -0
- package/lib/util/slugify.js +3 -0
- package/package.json +5 -4
- package/src/alchemy.ts +120 -0
- package/src/apply.ts +109 -114
- package/src/aws/bucket.ts +11 -14
- package/src/aws/function.ts +13 -33
- package/src/aws/index.ts +1 -0
- package/src/aws/oidc/github-oidc-provider.ts +14 -19
- package/src/aws/oidc/oidc-provider.ts +19 -12
- package/src/aws/policy-attachment.ts +51 -0
- package/src/aws/policy.ts +15 -60
- package/src/aws/queue.ts +17 -21
- package/src/aws/role.ts +25 -28
- package/src/aws/ses.ts +150 -164
- package/src/aws/table.ts +15 -15
- package/src/cloudflare/bindings.ts +8 -0
- package/src/cloudflare/bucket.ts +39 -47
- package/src/cloudflare/durable-object-namespace.ts +0 -10
- package/src/cloudflare/generate-asset-manifest.ts +1 -1
- package/src/cloudflare/kv-namespace.ts +35 -33
- package/src/cloudflare/static-site-router.ts +0 -3
- package/src/cloudflare/static-site.ts +44 -60
- package/src/cloudflare/worker.ts +105 -111
- package/src/context.ts +122 -0
- package/src/destroy.ts +124 -73
- package/src/{esbuild.ts → esbuild/bundle.ts} +16 -28
- package/src/esbuild/index.ts +1 -0
- package/src/fs/file.ts +39 -0
- package/src/fs/folder.ts +32 -0
- package/src/fs/index.ts +2 -0
- package/src/github/secret.ts +19 -16
- package/src/index.ts +7 -15
- package/src/resource.ts +101 -462
- package/src/scope.ts +101 -36
- package/src/secret.ts +9 -32
- package/src/state.ts +30 -21
- package/src/stripe/price.ts +17 -22
- package/src/stripe/product.ts +17 -22
- package/src/stripe/webhook.ts +21 -27
- package/src/test/bun.ts +105 -0
- package/src/util/serde.ts +53 -0
- package/src/util/slugify.ts +3 -0
- package/lib/$.d.ts +0 -12
- package/lib/$.d.ts.map +0 -1
- package/lib/$.js +0 -42
- package/lib/$.js.map +0 -1
- package/lib/alchemize.d.ts +0 -47
- package/lib/alchemize.d.ts.map +0 -1
- package/lib/alchemize.js +0 -116
- package/lib/alchemize.js.map +0 -1
- package/lib/apply.d.ts.map +0 -1
- package/lib/apply.js.map +0 -1
- package/lib/aws/account-id.d.ts.map +0 -1
- package/lib/aws/account-id.js.map +0 -1
- package/lib/aws/bucket.d.ts.map +0 -1
- package/lib/aws/bucket.js.map +0 -1
- package/lib/aws/function.d.ts.map +0 -1
- package/lib/aws/function.js.map +0 -1
- package/lib/aws/index.d.ts.map +0 -1
- package/lib/aws/index.js.map +0 -1
- package/lib/aws/oidc/github-oidc-provider.d.ts.map +0 -1
- package/lib/aws/oidc/github-oidc-provider.js.map +0 -1
- package/lib/aws/oidc/index.d.ts.map +0 -1
- package/lib/aws/oidc/index.js.map +0 -1
- package/lib/aws/oidc/oidc-provider.d.ts.map +0 -1
- package/lib/aws/oidc/oidc-provider.js.map +0 -1
- package/lib/aws/policy.d.ts.map +0 -1
- package/lib/aws/policy.js.map +0 -1
- package/lib/aws/queue.d.ts.map +0 -1
- package/lib/aws/queue.js.map +0 -1
- package/lib/aws/role.d.ts.map +0 -1
- package/lib/aws/role.js.map +0 -1
- package/lib/aws/ses.d.ts.map +0 -1
- package/lib/aws/ses.js.map +0 -1
- package/lib/aws/table.d.ts.map +0 -1
- package/lib/aws/table.js.map +0 -1
- package/lib/cloudflare/api.d.ts.map +0 -1
- package/lib/cloudflare/api.js.map +0 -1
- package/lib/cloudflare/asset-manifest.d.ts.map +0 -1
- package/lib/cloudflare/asset-manifest.js.map +0 -1
- package/lib/cloudflare/auth.d.ts.map +0 -1
- package/lib/cloudflare/auth.js.map +0 -1
- package/lib/cloudflare/bindings.d.ts.map +0 -1
- package/lib/cloudflare/bindings.js.map +0 -1
- package/lib/cloudflare/bound.d.ts.map +0 -1
- package/lib/cloudflare/bound.js.map +0 -1
- package/lib/cloudflare/bucket.d.ts.map +0 -1
- package/lib/cloudflare/bucket.js.map +0 -1
- package/lib/cloudflare/durable-object-namespace.d.ts.map +0 -1
- package/lib/cloudflare/durable-object-namespace.js.map +0 -1
- package/lib/cloudflare/generate-asset-manifest.d.ts.map +0 -1
- package/lib/cloudflare/generate-asset-manifest.js.map +0 -1
- package/lib/cloudflare/index.d.ts.map +0 -1
- package/lib/cloudflare/index.js.map +0 -1
- package/lib/cloudflare/kv-namespace.d.ts.map +0 -1
- package/lib/cloudflare/kv-namespace.js.map +0 -1
- package/lib/cloudflare/state.d.ts.map +0 -1
- package/lib/cloudflare/state.js.map +0 -1
- package/lib/cloudflare/static-site-router.d.ts.map +0 -1
- package/lib/cloudflare/static-site-router.js.map +0 -1
- package/lib/cloudflare/static-site.d.ts.map +0 -1
- package/lib/cloudflare/static-site.js.map +0 -1
- package/lib/cloudflare/types.d.ts.map +0 -1
- package/lib/cloudflare/types.js.map +0 -1
- package/lib/cloudflare/upload-asset-manifest.d.ts.map +0 -1
- package/lib/cloudflare/upload-asset-manifest.js.map +0 -1
- package/lib/cloudflare/worker-metadata.d.ts.map +0 -1
- package/lib/cloudflare/worker-metadata.js.map +0 -1
- package/lib/cloudflare/worker-migration.d.ts.map +0 -1
- package/lib/cloudflare/worker-migration.js.map +0 -1
- package/lib/cloudflare/worker.d.ts.map +0 -1
- package/lib/cloudflare/worker.js.map +0 -1
- package/lib/destroy.d.ts.map +0 -1
- package/lib/destroy.js.map +0 -1
- package/lib/encrypt.d.ts.map +0 -1
- package/lib/encrypt.js.map +0 -1
- package/lib/error.d.ts.map +0 -1
- package/lib/error.js.map +0 -1
- package/lib/esbuild.d.ts.map +0 -1
- package/lib/esbuild.js.map +0 -1
- package/lib/fs.d.ts +0 -12
- package/lib/fs.d.ts.map +0 -1
- package/lib/fs.js +0 -41
- package/lib/fs.js.map +0 -1
- package/lib/github/client.d.ts.map +0 -1
- package/lib/github/client.js.map +0 -1
- package/lib/github/index.d.ts.map +0 -1
- package/lib/github/index.js.map +0 -1
- package/lib/github/secret.d.ts.map +0 -1
- package/lib/github/secret.js.map +0 -1
- package/lib/global.d.ts +0 -16
- package/lib/global.d.ts.map +0 -1
- package/lib/global.js +0 -42
- package/lib/global.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/input.d.ts +0 -7
- package/lib/input.d.ts.map +0 -1
- package/lib/input.js +0 -2
- package/lib/input.js.map +0 -1
- package/lib/main.d.ts +0 -3
- package/lib/main.d.ts.map +0 -1
- package/lib/main.js +0 -32
- package/lib/main.js.map +0 -1
- package/lib/output.d.ts +0 -25
- package/lib/output.d.ts.map +0 -1
- package/lib/output.js +0 -23
- package/lib/output.js.map +0 -1
- package/lib/print.d.ts +0 -7
- package/lib/print.d.ts.map +0 -1
- package/lib/print.js +0 -10
- package/lib/print.js.map +0 -1
- package/lib/resource.d.ts.map +0 -1
- package/lib/resource.js.map +0 -1
- package/lib/scope.d.ts.map +0 -1
- package/lib/scope.js.map +0 -1
- package/lib/secret.d.ts.map +0 -1
- package/lib/secret.js.map +0 -1
- package/lib/serde.d.ts +0 -3
- package/lib/serde.d.ts.map +0 -1
- package/lib/serde.js.map +0 -1
- package/lib/slug.d.ts +0 -2
- package/lib/slug.d.ts.map +0 -1
- package/lib/slug.js +0 -4
- package/lib/slug.js.map +0 -1
- package/lib/state.d.ts.map +0 -1
- package/lib/state.js.map +0 -1
- package/lib/stripe/index.d.ts.map +0 -1
- package/lib/stripe/index.js.map +0 -1
- package/lib/stripe/price.d.ts.map +0 -1
- package/lib/stripe/price.js.map +0 -1
- package/lib/stripe/product.d.ts.map +0 -1
- package/lib/stripe/product.js.map +0 -1
- package/lib/stripe/webhook.d.ts.map +0 -1
- package/lib/stripe/webhook.js.map +0 -1
- package/lib/utils/content-type.d.ts.map +0 -1
- package/lib/utils/content-type.js.map +0 -1
- package/lib/utils/retry.d.ts.map +0 -1
- package/lib/utils/retry.js.map +0 -1
- package/src/$.ts +0 -69
- package/src/alchemize.ts +0 -195
- package/src/fs.ts +0 -47
- package/src/global.ts +0 -63
- package/src/input.ts +0 -19
- package/src/main.ts +0 -34
- package/src/output.ts +0 -75
- package/src/print.ts +0 -18
- package/src/serde.ts +0 -46
- package/src/slug.ts +0 -3
- /package/src/{utils → util}/content-type.ts +0 -0
- /package/src/{encrypt.ts → util/encrypt.ts} +0 -0
- /package/src/{error.ts → util/ignore.ts} +0 -0
- /package/src/{utils → util}/retry.ts +0 -0
package/lib/alchemy.d.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { destroy } from "./destroy";
|
|
2
|
+
import { Scope } from "./scope";
|
|
3
|
+
import { secret } from "./secret";
|
|
4
|
+
import type { StateStoreType } from "./state";
|
|
5
|
+
export type alchemy = Alchemy;
|
|
6
|
+
export declare const alchemy: Alchemy;
|
|
7
|
+
export interface Alchemy {
|
|
8
|
+
scope: typeof scope;
|
|
9
|
+
run: typeof run;
|
|
10
|
+
destroy: typeof destroy;
|
|
11
|
+
secret: typeof secret;
|
|
12
|
+
(...parameters: Parameters<typeof scope>): ReturnType<typeof scope>;
|
|
13
|
+
}
|
|
14
|
+
export interface AlchemyOptions {
|
|
15
|
+
/**
|
|
16
|
+
* The name of the application.
|
|
17
|
+
*/
|
|
18
|
+
appName?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Determines whether the resources will be created/updated or deleted.
|
|
21
|
+
*
|
|
22
|
+
* @default "up"
|
|
23
|
+
*/
|
|
24
|
+
phase?: "up" | "destroy";
|
|
25
|
+
/**
|
|
26
|
+
* Name to scope the resource state under (e.g. `.alchemy/{stage}/..`).
|
|
27
|
+
*
|
|
28
|
+
* @default - your POSIX username
|
|
29
|
+
*/
|
|
30
|
+
stage?: string;
|
|
31
|
+
/**
|
|
32
|
+
* If true, will not prune resources that were dropped from the root stack.
|
|
33
|
+
*
|
|
34
|
+
* @default true
|
|
35
|
+
*/
|
|
36
|
+
destroyOrphans?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* A custom state store to use instead of the default file system store.
|
|
39
|
+
*/
|
|
40
|
+
stateStore?: StateStoreType;
|
|
41
|
+
/**
|
|
42
|
+
* A custom scope to use as a parent.
|
|
43
|
+
*/
|
|
44
|
+
parent?: Scope;
|
|
45
|
+
/**
|
|
46
|
+
* If true, will not print any Create/Update/Delete messages.
|
|
47
|
+
*
|
|
48
|
+
* @default false
|
|
49
|
+
*/
|
|
50
|
+
quiet?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* A passphrase to use to encrypt/decrypt secrets.
|
|
53
|
+
*/
|
|
54
|
+
password?: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Enter a new scope synchronously.
|
|
58
|
+
* @param options
|
|
59
|
+
* @returns
|
|
60
|
+
*/
|
|
61
|
+
declare function scope(id: string | undefined, options?: AlchemyOptions): Scope;
|
|
62
|
+
declare function run<T>(...args: [id: string, fn: (this: Scope, scope: Scope) => Promise<T>] | [
|
|
63
|
+
id: string,
|
|
64
|
+
options: AlchemyOptions,
|
|
65
|
+
fn: (this: Scope, scope: Scope) => Promise<T>
|
|
66
|
+
]): Promise<T>;
|
|
67
|
+
export {};
|
package/lib/alchemy.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { destroy } from "./destroy";
|
|
2
|
+
import { Scope } from "./scope";
|
|
3
|
+
import { secret } from "./secret";
|
|
4
|
+
// TODO: support browser
|
|
5
|
+
const DEFAULT_STAGE = process.env.ALCHEMY_STAGE ?? process.env.USER ?? "dev";
|
|
6
|
+
function _alchemy(appName, options) {
|
|
7
|
+
return scope(undefined, {
|
|
8
|
+
...options,
|
|
9
|
+
appName,
|
|
10
|
+
stage: options.stage,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
_alchemy.destroy = destroy;
|
|
14
|
+
_alchemy.run = run;
|
|
15
|
+
_alchemy.scope = scope;
|
|
16
|
+
_alchemy.secret = secret;
|
|
17
|
+
export const alchemy = _alchemy;
|
|
18
|
+
/**
|
|
19
|
+
* Enter a new scope synchronously.
|
|
20
|
+
* @param options
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
function scope(id, options) {
|
|
24
|
+
const scope = new Scope({
|
|
25
|
+
...options,
|
|
26
|
+
appName: options?.appName,
|
|
27
|
+
stage: options?.stage ?? DEFAULT_STAGE,
|
|
28
|
+
scopeName: id,
|
|
29
|
+
parent: options?.parent ?? Scope.get(),
|
|
30
|
+
});
|
|
31
|
+
scope.enter();
|
|
32
|
+
return scope;
|
|
33
|
+
}
|
|
34
|
+
async function run(...args) {
|
|
35
|
+
const [id, options, fn] = typeof args[1] === "function"
|
|
36
|
+
? [args[0], undefined, args[1]]
|
|
37
|
+
: args;
|
|
38
|
+
await using scope = alchemy.scope(id, options);
|
|
39
|
+
return await fn.bind(scope)(scope);
|
|
40
|
+
}
|
package/lib/apply.d.ts
CHANGED
|
@@ -1,23 +1,6 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import { type Scope as IScope } from "./scope";
|
|
3
|
-
import type { StateStore } from "./state";
|
|
1
|
+
import { type PendingResource, type Resource, type ResourceProps } from "./resource";
|
|
4
2
|
export interface ApplyOptions {
|
|
5
|
-
stage: string;
|
|
6
|
-
scope: IScope;
|
|
7
|
-
stateStore: StateStore;
|
|
8
3
|
quiet?: boolean;
|
|
4
|
+
alwaysUpdate?: boolean;
|
|
9
5
|
}
|
|
10
|
-
|
|
11
|
-
* Apply a sub-graph to produce a resource.
|
|
12
|
-
* @param output A sub-graph that produces a resource.
|
|
13
|
-
* @returns The resource properties.
|
|
14
|
-
*/
|
|
15
|
-
export declare function apply<T>(output: T, options?: Partial<ApplyOptions>): Promise<Resolved<T>>;
|
|
16
|
-
declare class Evaluated<T> {
|
|
17
|
-
readonly value: T;
|
|
18
|
-
readonly deps: string[];
|
|
19
|
-
constructor(value: T, deps?: string[]);
|
|
20
|
-
}
|
|
21
|
-
export declare function evaluate<T>(output: T | Output<T>, options: ApplyOptions): Promise<Evaluated<T>>;
|
|
22
|
-
export {};
|
|
23
|
-
//# sourceMappingURL=apply.d.ts.map
|
|
6
|
+
export declare function apply<Out extends Resource>(resource: PendingResource<Out>, props: ResourceProps, options?: ApplyOptions): Promise<Awaited<Out>>;
|
package/lib/apply.js
CHANGED
|
@@ -1,88 +1,92 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const scope = options?.scope ?? getScope();
|
|
14
|
-
const statePath = scope.getScopePath(stage);
|
|
15
|
-
const stateStore = options?.stateStore ?? new defaultStateStore(statePath);
|
|
16
|
-
return (await evaluate(output, { stage, scope, stateStore, quiet: options?.quiet })).value;
|
|
17
|
-
}
|
|
18
|
-
class Evaluated {
|
|
19
|
-
value;
|
|
20
|
-
deps;
|
|
21
|
-
constructor(value, deps = []) {
|
|
22
|
-
this.value = value;
|
|
23
|
-
this.deps = deps;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
const cache = new WeakMap();
|
|
27
|
-
export async function evaluate(output, options) {
|
|
28
|
-
const stage = options.stage;
|
|
29
|
-
const stateStore = options.stateStore;
|
|
30
|
-
if (isResource(output)) {
|
|
31
|
-
const resource = output;
|
|
32
|
-
const resourceID = resource[ResourceID];
|
|
33
|
-
const evaluated = await Promise.all(resource[Input].map((r) => evaluate(r, options)));
|
|
34
|
-
if (cache.has(resource)) {
|
|
35
|
-
return await cache.get(resource);
|
|
36
|
-
}
|
|
37
|
-
let resolve;
|
|
38
|
-
let reject;
|
|
39
|
-
const promise = new Promise((res, rej) => {
|
|
40
|
-
resolve = res;
|
|
41
|
-
reject = rej;
|
|
42
|
-
});
|
|
43
|
-
// set this eagerly to avoid double-apply (caused by recursive applies to inputs)
|
|
44
|
-
cache.set(resource, promise);
|
|
45
|
-
const deps = new Set(evaluated.flatMap((input) => input.deps));
|
|
46
|
-
const inputs = evaluated.map((input) => input.value);
|
|
47
|
-
try {
|
|
48
|
-
const result = await resource[Provider].update(stage, resource, deps, inputs, stateStore, options);
|
|
49
|
-
resolve(new Evaluated(result, [resourceID, ...deps]));
|
|
50
|
-
}
|
|
51
|
-
catch (error) {
|
|
52
|
-
console.error(error);
|
|
53
|
-
reject(error);
|
|
54
|
-
}
|
|
55
|
-
return promise;
|
|
1
|
+
import { alchemy } from "./alchemy";
|
|
2
|
+
import { context } from "./context";
|
|
3
|
+
import { PROVIDERS, } from "./resource";
|
|
4
|
+
import { serialize } from "./util/serde";
|
|
5
|
+
export async function apply(resource, props, options) {
|
|
6
|
+
const scope = resource.Scope;
|
|
7
|
+
const quiet = props.quiet ?? scope.quiet;
|
|
8
|
+
await scope.init();
|
|
9
|
+
let state = (await scope.state.get(resource.ID));
|
|
10
|
+
const provider = PROVIDERS.get(resource.Kind);
|
|
11
|
+
if (provider === undefined) {
|
|
12
|
+
throw new Error(`Provider "${resource.Kind}" not found`);
|
|
56
13
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
14
|
+
if (state === undefined) {
|
|
15
|
+
state = {
|
|
16
|
+
kind: resource.Kind,
|
|
17
|
+
id: resource.ID,
|
|
18
|
+
fqn: resource.FQN,
|
|
19
|
+
seq: resource.Seq,
|
|
20
|
+
status: "creating",
|
|
21
|
+
data: {},
|
|
22
|
+
output: {
|
|
23
|
+
ID: resource.ID,
|
|
24
|
+
FQN: resource.FQN,
|
|
25
|
+
Kind: resource.Kind,
|
|
26
|
+
Scope: scope,
|
|
27
|
+
Seq: resource.Seq,
|
|
28
|
+
},
|
|
29
|
+
// deps: [...deps],
|
|
30
|
+
props,
|
|
31
|
+
};
|
|
32
|
+
await scope.state.set(resource.ID, state);
|
|
67
33
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
34
|
+
const alwaysUpdate = options?.alwaysUpdate ?? provider.options?.alwaysUpdate ?? false;
|
|
35
|
+
// Skip update if inputs haven't changed and resource is in a stable state
|
|
36
|
+
if (state.status === "created" || state.status === "updated") {
|
|
37
|
+
if (JSON.stringify(state.props) === JSON.stringify(serialize(scope, props)) &&
|
|
38
|
+
alwaysUpdate !== true) {
|
|
39
|
+
if (!quiet) {
|
|
40
|
+
console.log(`Skip: "${resource.FQN}" (no changes)`);
|
|
41
|
+
}
|
|
42
|
+
// if (resourceState.output !== undefined) {
|
|
43
|
+
// resource[Provide](resourceState.output);
|
|
44
|
+
// }
|
|
45
|
+
return state.output;
|
|
46
|
+
}
|
|
74
47
|
}
|
|
75
|
-
|
|
76
|
-
|
|
48
|
+
const phase = state.status === "creating" ? "create" : "update";
|
|
49
|
+
state.status = phase === "create" ? "creating" : "updating";
|
|
50
|
+
state.oldProps = state.props;
|
|
51
|
+
state.props = props;
|
|
52
|
+
if (!quiet) {
|
|
53
|
+
console.log(`${phase === "create" ? "Create" : "Update"}: "${resource.FQN}"`);
|
|
77
54
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
55
|
+
await scope.state.set(resource.ID, state);
|
|
56
|
+
let isReplaced = false;
|
|
57
|
+
const ctx = context({
|
|
58
|
+
scope,
|
|
59
|
+
phase,
|
|
60
|
+
kind: resource.Kind,
|
|
61
|
+
id: resource.ID,
|
|
62
|
+
fqn: resource.FQN,
|
|
63
|
+
seq: resource.Seq,
|
|
64
|
+
state,
|
|
65
|
+
replace: () => {
|
|
66
|
+
if (isReplaced) {
|
|
67
|
+
console.warn(`Resource ${resource.Kind} ${resource.FQN} is already marked as REPLACE`);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
isReplaced = true;
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
const output = await alchemy.run(resource.ID, async () => provider.handler.bind(ctx)(resource.ID, props));
|
|
74
|
+
if (!quiet) {
|
|
75
|
+
console.log(`${phase === "create" ? "Created" : "Updated"}: "${resource.FQN}"`);
|
|
84
76
|
}
|
|
85
|
-
|
|
86
|
-
|
|
77
|
+
await scope.state.set(resource.ID, {
|
|
78
|
+
kind: resource.Kind,
|
|
79
|
+
id: resource.ID,
|
|
80
|
+
fqn: resource.FQN,
|
|
81
|
+
seq: resource.Seq,
|
|
82
|
+
data: state.data,
|
|
83
|
+
status: phase === "create" ? "created" : "updated",
|
|
84
|
+
output,
|
|
85
|
+
props,
|
|
86
|
+
// deps: [...deps],
|
|
87
|
+
});
|
|
88
|
+
// if (output !== undefined) {
|
|
89
|
+
// resource[Provide](output as Out);
|
|
90
|
+
// }
|
|
91
|
+
return output;
|
|
87
92
|
}
|
|
88
|
-
//# sourceMappingURL=apply.js.map
|
package/lib/aws/account-id.d.ts
CHANGED
package/lib/aws/account-id.js
CHANGED
package/lib/aws/bucket.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import type { Context } from "../context";
|
|
2
|
+
import { Resource } from "../resource";
|
|
1
3
|
export interface BucketProps {
|
|
2
4
|
bucketName: string;
|
|
3
5
|
tags?: Record<string, string>;
|
|
4
6
|
}
|
|
5
|
-
export interface
|
|
6
|
-
id: string;
|
|
7
|
+
export interface Bucket extends Resource<"s3::Bucket">, BucketProps {
|
|
7
8
|
arn: string;
|
|
8
9
|
bucketDomainName: string;
|
|
9
10
|
bucketRegionalDomainName?: string;
|
|
@@ -14,8 +15,4 @@ export interface BucketOutput extends BucketProps {
|
|
|
14
15
|
versioningEnabled?: boolean;
|
|
15
16
|
acl?: string;
|
|
16
17
|
}
|
|
17
|
-
declare const
|
|
18
|
-
export declare class Bucket extends Bucket_base {
|
|
19
|
-
}
|
|
20
|
-
export {};
|
|
21
|
-
//# sourceMappingURL=bucket.d.ts.map
|
|
18
|
+
export declare const Bucket: ((this: Context<Bucket>, id: string, props: BucketProps) => Promise<Bucket>) | (((this: any, id: string, props: BucketProps) => never) & (new (_: never) => never));
|
package/lib/aws/bucket.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { CreateBucketCommand, DeleteBucketCommand, GetBucketAclCommand, GetBucketLocationCommand, GetBucketTaggingCommand, GetBucketVersioningCommand, HeadBucketCommand, NoSuchBucket, PutBucketTaggingCommand, S3Client, } from "@aws-sdk/client-s3";
|
|
2
|
-
import { ignore } from "../error";
|
|
3
2
|
import { Resource } from "../resource";
|
|
4
|
-
|
|
3
|
+
import { ignore } from "../util/ignore";
|
|
4
|
+
export const Bucket = Resource("s3::Bucket", async function (id, props) {
|
|
5
5
|
const client = new S3Client({});
|
|
6
|
-
if (
|
|
6
|
+
if (this.phase === "delete") {
|
|
7
7
|
await ignore(NoSuchBucket.name, () => client.send(new DeleteBucketCommand({
|
|
8
8
|
Bucket: props.bucketName,
|
|
9
9
|
})));
|
|
10
|
-
return
|
|
10
|
+
return this.destroy();
|
|
11
11
|
}
|
|
12
12
|
else {
|
|
13
13
|
try {
|
|
@@ -16,7 +16,7 @@ export class Bucket extends Resource("s3::Bucket", async (ctx, props) => {
|
|
|
16
16
|
Bucket: props.bucketName,
|
|
17
17
|
}));
|
|
18
18
|
// Update tags if they changed and bucket exists
|
|
19
|
-
if (
|
|
19
|
+
if (this.phase === "update" && props.tags) {
|
|
20
20
|
await client.send(new PutBucketTaggingCommand({
|
|
21
21
|
Bucket: props.bucketName,
|
|
22
22
|
Tagging: {
|
|
@@ -68,9 +68,8 @@ export class Bucket extends Resource("s3::Bucket", async (ctx, props) => {
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
-
|
|
71
|
+
return this({
|
|
72
72
|
bucketName: props.bucketName,
|
|
73
|
-
id: props.bucketName,
|
|
74
73
|
arn: `arn:aws:s3:::${props.bucketName}`,
|
|
75
74
|
bucketDomainName: `${props.bucketName}.s3.amazonaws.com`,
|
|
76
75
|
bucketRegionalDomainName: `${props.bucketName}.s3.${region}.amazonaws.com`,
|
|
@@ -79,11 +78,9 @@ export class Bucket extends Resource("s3::Bucket", async (ctx, props) => {
|
|
|
79
78
|
versioningEnabled: versioningResponse.Status === "Enabled",
|
|
80
79
|
acl: aclResponse.Grants?.[0]?.Permission?.toLowerCase(),
|
|
81
80
|
...(tags && { tags }),
|
|
82
|
-
};
|
|
83
|
-
return output;
|
|
81
|
+
});
|
|
84
82
|
}
|
|
85
|
-
})
|
|
86
|
-
}
|
|
83
|
+
});
|
|
87
84
|
// Helper function to get S3 hosted zone IDs by region
|
|
88
85
|
function getHostedZoneId(region) {
|
|
89
86
|
const hostedZoneIds = {
|
|
@@ -111,4 +108,3 @@ function getHostedZoneId(region) {
|
|
|
111
108
|
};
|
|
112
109
|
return hostedZoneIds[region] || "Z3AQBSTGFYJSTF"; // Default to us-east-1 if region not found
|
|
113
110
|
}
|
|
114
|
-
//# sourceMappingURL=bucket.js.map
|
package/lib/aws/function.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Architecture, Runtime } from "@aws-sdk/client-lambda";
|
|
2
|
+
import type { Context } from "../context";
|
|
3
|
+
import { Resource } from "../resource";
|
|
2
4
|
export interface FunctionProps {
|
|
3
5
|
functionName: string;
|
|
4
6
|
zipPath: string;
|
|
@@ -23,8 +25,7 @@ export interface FunctionProps {
|
|
|
23
25
|
};
|
|
24
26
|
};
|
|
25
27
|
}
|
|
26
|
-
export interface
|
|
27
|
-
id: string;
|
|
28
|
+
export interface Function extends Resource<"lambda::Function">, FunctionProps {
|
|
28
29
|
arn: string;
|
|
29
30
|
lastModified: string;
|
|
30
31
|
version: string;
|
|
@@ -46,8 +47,4 @@ export interface FunctionOutput extends FunctionProps {
|
|
|
46
47
|
signingProfileVersionArn?: string;
|
|
47
48
|
signingJobArn?: string;
|
|
48
49
|
}
|
|
49
|
-
declare const
|
|
50
|
-
export declare class Function extends Function_base {
|
|
51
|
-
}
|
|
52
|
-
export {};
|
|
53
|
-
//# sourceMappingURL=function.d.ts.map
|
|
50
|
+
export declare const Function: ((this: Context<Function>, id: string, props: FunctionProps) => Promise<Function>) | (((this: any, id: string, props: FunctionProps) => never) & (new (_: never) => never));
|
package/lib/aws/function.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Architecture, CreateFunctionCommand, DeleteFunctionCommand, GetFunctionCommand, GetFunctionConfigurationCommand, LambdaClient, ResourceNotFoundException, Runtime, UpdateFunctionCodeCommand, UpdateFunctionConfigurationCommand, } from "@aws-sdk/client-lambda";
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import { ignore } from "../error";
|
|
5
4
|
import { Resource } from "../resource";
|
|
5
|
+
import { ignore } from "../util/ignore";
|
|
6
6
|
async function resolveRegion(client) {
|
|
7
7
|
const region = client.config.region;
|
|
8
8
|
if (typeof region === "string")
|
|
@@ -11,40 +11,23 @@ async function resolveRegion(client) {
|
|
|
11
11
|
return region();
|
|
12
12
|
throw new Error("Could not resolve AWS region");
|
|
13
13
|
}
|
|
14
|
-
export
|
|
14
|
+
export const Function = Resource("lambda::Function", async function (id, props) {
|
|
15
15
|
const client = new LambdaClient({});
|
|
16
16
|
const region = await resolveRegion(client);
|
|
17
17
|
const code = await zipCode(props.zipPath);
|
|
18
|
-
if (
|
|
18
|
+
if (this.phase === "delete") {
|
|
19
19
|
await ignore(ResourceNotFoundException.name, () => client.send(new DeleteFunctionCommand({
|
|
20
20
|
FunctionName: props.functionName,
|
|
21
21
|
})));
|
|
22
|
-
|
|
23
|
-
return {
|
|
24
|
-
...props,
|
|
25
|
-
id: props.functionName,
|
|
26
|
-
arn: `arn:aws:lambda:${region}:${process.env.AWS_ACCOUNT_ID}:function:${props.functionName}`,
|
|
27
|
-
lastModified: new Date().toISOString(),
|
|
28
|
-
version: "$LATEST",
|
|
29
|
-
qualifiedArn: `arn:aws:lambda:${region}:${process.env.AWS_ACCOUNT_ID}:function:${props.functionName}:$LATEST`,
|
|
30
|
-
invokeArn: `arn:aws:apigateway:${region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${region}:${process.env.AWS_ACCOUNT_ID}:function:${props.functionName}/invocations`,
|
|
31
|
-
sourceCodeHash: "",
|
|
32
|
-
sourceCodeSize: 0,
|
|
33
|
-
architectures: props.architecture
|
|
34
|
-
? [props.architecture]
|
|
35
|
-
: [Architecture.x86_64],
|
|
36
|
-
revisionId: "",
|
|
37
|
-
state: "Inactive",
|
|
38
|
-
packageType: "Zip",
|
|
39
|
-
};
|
|
22
|
+
return this.destroy();
|
|
40
23
|
}
|
|
41
24
|
else {
|
|
42
25
|
try {
|
|
43
26
|
// Check if function exists
|
|
44
|
-
|
|
27
|
+
await client.send(new GetFunctionCommand({
|
|
45
28
|
FunctionName: props.functionName,
|
|
46
29
|
}));
|
|
47
|
-
if (
|
|
30
|
+
if (this.phase === "update") {
|
|
48
31
|
// Wait for function to stabilize
|
|
49
32
|
await waitForFunctionStabilization(client, props.functionName);
|
|
50
33
|
// Update function code
|
|
@@ -134,9 +117,8 @@ export class Function extends Resource("lambda::Function", async (ctx, props) =>
|
|
|
134
117
|
FunctionName: props.functionName,
|
|
135
118
|
})),
|
|
136
119
|
]);
|
|
137
|
-
|
|
120
|
+
return this({
|
|
138
121
|
...props,
|
|
139
|
-
id: props.functionName,
|
|
140
122
|
arn: config.FunctionArn,
|
|
141
123
|
lastModified: config.LastModified,
|
|
142
124
|
version: config.Version,
|
|
@@ -157,11 +139,9 @@ export class Function extends Resource("lambda::Function", async (ctx, props) =>
|
|
|
157
139
|
packageType: config.PackageType,
|
|
158
140
|
signingProfileVersionArn: config.SigningProfileVersionArn,
|
|
159
141
|
signingJobArn: config.SigningJobArn,
|
|
160
|
-
};
|
|
161
|
-
return output;
|
|
142
|
+
});
|
|
162
143
|
}
|
|
163
|
-
})
|
|
164
|
-
}
|
|
144
|
+
});
|
|
165
145
|
// Helper to wait for function to stabilize
|
|
166
146
|
async function waitForFunctionStabilization(client, functionName) {
|
|
167
147
|
while (true) {
|
|
@@ -192,4 +172,3 @@ async function zipCode(filePath) {
|
|
|
192
172
|
platform: "UNIX",
|
|
193
173
|
});
|
|
194
174
|
}
|
|
195
|
-
//# sourceMappingURL=function.js.map
|
package/lib/aws/index.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ export * from "./account-id";
|
|
|
2
2
|
export * from "./bucket";
|
|
3
3
|
export * from "./function";
|
|
4
4
|
export * from "./policy";
|
|
5
|
+
export * from "./policy-attachment";
|
|
5
6
|
export * from "./queue";
|
|
6
7
|
export * from "./role";
|
|
7
8
|
export * from "./ses";
|
|
8
9
|
export * from "./table";
|
|
9
|
-
//# sourceMappingURL=index.d.ts.map
|
package/lib/aws/index.js
CHANGED
|
@@ -2,8 +2,8 @@ export * from "./account-id";
|
|
|
2
2
|
export * from "./bucket";
|
|
3
3
|
export * from "./function";
|
|
4
4
|
export * from "./policy";
|
|
5
|
+
export * from "./policy-attachment";
|
|
5
6
|
export * from "./queue";
|
|
6
7
|
export * from "./role";
|
|
7
8
|
export * from "./ses";
|
|
8
9
|
export * from "./table";
|
|
9
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import type { Input } from "../../input";
|
|
2
1
|
import { OIDCProvider, type OIDCProviderProps } from "./oidc-provider";
|
|
3
2
|
export interface GitHubOIDCProviderProps extends Omit<OIDCProviderProps, "thumbprint"> {
|
|
4
3
|
owner: string;
|
|
5
4
|
repository: string;
|
|
6
|
-
thumbprint?: string;
|
|
7
5
|
}
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=github-oidc-provider.d.ts.map
|
|
6
|
+
export type GitHubOIDCProvider = ReturnType<typeof GitHubOIDCProvider>;
|
|
7
|
+
export declare const GitHubOIDCProvider: (id: string, props: GitHubOIDCProviderProps) => Promise<OIDCProvider>;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { isOutput } from "../../output";
|
|
2
1
|
import { OIDCProvider } from "./oidc-provider";
|
|
3
2
|
/**
|
|
4
3
|
* Default thumbprint for GitHub's OIDC provider
|
|
@@ -6,17 +5,13 @@ import { OIDCProvider } from "./oidc-provider";
|
|
|
6
5
|
* @see https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services#adding-the-identity-provider-to-aws
|
|
7
6
|
*/
|
|
8
7
|
const DEFAULT_GITHUB_THUMBPRINT = "6938fd4d98bab03faadb97b34396831e3780aea1";
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=github-oidc-provider.js.map
|
|
8
|
+
export const GitHubOIDCProvider = async (id, props) => {
|
|
9
|
+
return OIDCProvider(id, {
|
|
10
|
+
owner: props.owner,
|
|
11
|
+
repository: props.repository,
|
|
12
|
+
roleArn: props.roleArn,
|
|
13
|
+
branches: props.branches,
|
|
14
|
+
environments: props.environments,
|
|
15
|
+
thumbprint: DEFAULT_GITHUB_THUMBPRINT,
|
|
16
|
+
});
|
|
17
|
+
};
|
package/lib/aws/oidc/index.d.ts
CHANGED
package/lib/aws/oidc/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { Context } from "../../context";
|
|
2
|
+
import { Resource } from "../../resource";
|
|
1
3
|
/**
|
|
2
4
|
* Properties for configuring an AWS OIDC provider for GitHub Actions
|
|
3
5
|
*/
|
|
@@ -40,7 +42,7 @@ export interface OIDCProviderProps {
|
|
|
40
42
|
/**
|
|
41
43
|
* Output returned after OIDC provider configuration
|
|
42
44
|
*/
|
|
43
|
-
export interface
|
|
45
|
+
export interface OIDCProvider extends Resource<"aws::OIDCProvider">, OIDCProviderProps {
|
|
44
46
|
/**
|
|
45
47
|
* The ARN of the OIDC provider
|
|
46
48
|
*/
|
|
@@ -50,11 +52,7 @@ export interface OIDCProviderOutput extends OIDCProviderProps {
|
|
|
50
52
|
*/
|
|
51
53
|
createdAt: number;
|
|
52
54
|
}
|
|
53
|
-
declare const OIDCProvider_base: import("../../resource").Provider<"aws::OIDCProvider", [props: OIDCProviderProps], OIDCProviderOutput>;
|
|
54
55
|
/**
|
|
55
56
|
* Resource for configuring AWS OIDC provider for GitHub Actions
|
|
56
57
|
*/
|
|
57
|
-
export declare
|
|
58
|
-
}
|
|
59
|
-
export {};
|
|
60
|
-
//# sourceMappingURL=oidc-provider.d.ts.map
|
|
58
|
+
export declare const OIDCProvider: ((this: Context<OIDCProvider>, id: string, props: OIDCProviderProps) => Promise<OIDCProvider>) | (((this: any, id: string, props: OIDCProviderProps) => never) & (new (_: never) => never));
|