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/context.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { DestroyedSignal } from "./destroy";
|
|
2
|
+
export function context({ scope, phase, kind, id, fqn, seq, state, replace, }) {
|
|
3
|
+
function create(props) {
|
|
4
|
+
return {
|
|
5
|
+
...props,
|
|
6
|
+
Kind: kind,
|
|
7
|
+
ID: id,
|
|
8
|
+
FQN: fqn,
|
|
9
|
+
Scope: scope,
|
|
10
|
+
Seq: seq,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
return Object.assign(create, {
|
|
14
|
+
stage: scope.stage,
|
|
15
|
+
scope,
|
|
16
|
+
id: id,
|
|
17
|
+
fqn: fqn,
|
|
18
|
+
phase,
|
|
19
|
+
output: state.output,
|
|
20
|
+
replace,
|
|
21
|
+
get: (key) => state.data[key],
|
|
22
|
+
set: async (key, value) => {
|
|
23
|
+
state.data[key] = value;
|
|
24
|
+
},
|
|
25
|
+
delete: async (key) => {
|
|
26
|
+
const value = state.data[key];
|
|
27
|
+
delete state.data[key];
|
|
28
|
+
return value;
|
|
29
|
+
},
|
|
30
|
+
quiet: scope.quiet,
|
|
31
|
+
destroy: () => {
|
|
32
|
+
throw new DestroyedSignal();
|
|
33
|
+
},
|
|
34
|
+
create,
|
|
35
|
+
});
|
|
36
|
+
}
|
package/lib/destroy.d.ts
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { type Resource } from "./resource";
|
|
2
|
+
import { Scope } from "./scope";
|
|
3
|
+
export declare class DestroyedSignal extends Error {
|
|
4
|
+
}
|
|
5
5
|
export interface DestroyOptions {
|
|
6
|
-
stage?: string;
|
|
7
|
-
stateStore?: StateStore;
|
|
8
|
-
scope?: Scope;
|
|
9
6
|
quiet?: boolean;
|
|
7
|
+
strategy?: "sequential" | "parallel";
|
|
10
8
|
}
|
|
11
9
|
/**
|
|
12
10
|
* Prune all resources from an Output and "down", i.e. that branches from it.
|
|
13
11
|
*/
|
|
14
|
-
export declare function destroy<
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
//# sourceMappingURL=destroy.d.ts.map
|
|
12
|
+
export declare function destroy<Type extends string>(...args: [scope: Scope, options?: DestroyOptions] | [resource: Resource<Type> | undefined | null, options?: DestroyOptions]): Promise<void>;
|
|
13
|
+
export declare namespace destroy {
|
|
14
|
+
function all(resources: Resource[], options?: DestroyOptions): Promise<void>;
|
|
15
|
+
function sequentially(...resources: (Resource<string> | undefined | null)[]): Promise<void>;
|
|
16
|
+
}
|
package/lib/destroy.js
CHANGED
|
@@ -1,54 +1,115 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { alchemy } from "./alchemy";
|
|
2
|
+
import { context } from "./context";
|
|
3
|
+
import { PROVIDERS } from "./resource";
|
|
4
|
+
import { Scope } from "./scope";
|
|
5
|
+
export class DestroyedSignal extends Error {
|
|
6
|
+
}
|
|
7
|
+
function isScopeArgs(a) {
|
|
8
|
+
return a[0] instanceof Scope;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Prune all resources from an Output and "down", i.e. that branches from it.
|
|
12
|
+
*/
|
|
4
13
|
export async function destroy(...args) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
else if (isResource(args[0])) {
|
|
22
|
-
const resource = args[0];
|
|
23
|
-
// stage = args[1]?.stage ?? defaultStage;
|
|
24
|
-
resourceID = resource[ResourceID];
|
|
25
|
-
stage = args[1]?.stage ?? defaultStage;
|
|
26
|
-
scope = args[1]?.scope ?? rootScope;
|
|
27
|
-
const statePath = scope.getScopePath(stage);
|
|
28
|
-
stateStore = args[1]?.stateStore ?? new defaultStateStore(statePath);
|
|
29
|
-
// First destroy all dependencies
|
|
30
|
-
const _resourceState = await stateStore.get(resourceID);
|
|
31
|
-
if (_resourceState === undefined) {
|
|
32
|
-
// we have no record of this resource, we must assume it's already deleted
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
resourceState = _resourceState;
|
|
36
|
-
resourceProvider = resource[Provider];
|
|
37
|
-
options = args[1];
|
|
14
|
+
if (isScopeArgs(args)) {
|
|
15
|
+
const [scope, options] = args;
|
|
16
|
+
const strategy = options?.strategy ?? "sequential";
|
|
17
|
+
// destroy all active resources
|
|
18
|
+
await destroy.all(Array.from(scope.resources.values()), {
|
|
19
|
+
strategy,
|
|
20
|
+
});
|
|
21
|
+
// then detect orphans and destroy them
|
|
22
|
+
const orphans = await scope.state.all();
|
|
23
|
+
await destroy.all(Object.values(orphans).map((orphan) => ({
|
|
24
|
+
...orphan.output,
|
|
25
|
+
Scope: scope,
|
|
26
|
+
})), options);
|
|
27
|
+
// finally, destroy the scope container
|
|
28
|
+
await scope.deinit();
|
|
29
|
+
return;
|
|
38
30
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
31
|
+
const [instance, options] = args;
|
|
32
|
+
if (!instance) {
|
|
33
|
+
return;
|
|
42
34
|
}
|
|
35
|
+
const Provider = PROVIDERS.get(instance.Kind);
|
|
36
|
+
if (!Provider) {
|
|
37
|
+
throw new Error(`Cannot destroy resource type ${instance.Kind} - no provider found. You may need to import the provider in your alchemy.config.ts.`);
|
|
38
|
+
}
|
|
39
|
+
const scope = instance.Scope;
|
|
40
|
+
if (!scope) {
|
|
41
|
+
console.warn(`Resource "${instance.FQN}" has no scope`);
|
|
42
|
+
}
|
|
43
|
+
const quiet = options?.quiet ?? scope.quiet;
|
|
43
44
|
try {
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
if (!quiet) {
|
|
46
|
+
console.log(`Delete: "${instance.FQN}"`);
|
|
47
|
+
}
|
|
48
|
+
const state = (await scope.state.get(instance.ID));
|
|
49
|
+
if (state === undefined) {
|
|
50
|
+
console.warn(`Resource "${instance.FQN}" not found`);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const ctx = context({
|
|
54
|
+
scope,
|
|
55
|
+
phase: "delete",
|
|
56
|
+
kind: instance.Kind,
|
|
57
|
+
id: instance.ID,
|
|
58
|
+
fqn: instance.FQN,
|
|
59
|
+
seq: instance.Seq,
|
|
60
|
+
state,
|
|
61
|
+
replace: () => {
|
|
62
|
+
throw new Error("Cannot replace a resource that is being deleted");
|
|
63
|
+
},
|
|
46
64
|
});
|
|
65
|
+
let nestedScope;
|
|
66
|
+
try {
|
|
67
|
+
// BUG: this does not restore persisted scope
|
|
68
|
+
await alchemy.run(instance.ID, async (scope) => {
|
|
69
|
+
nestedScope = scope;
|
|
70
|
+
return Provider.handler.bind(ctx)(instance.ID, state.props);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
if (err instanceof DestroyedSignal) {
|
|
75
|
+
// TODO: should we fail if the DestroyedSignal is not thrown?
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
throw err;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (nestedScope) {
|
|
82
|
+
await destroy(nestedScope, options);
|
|
83
|
+
}
|
|
84
|
+
await scope.delete(instance.ID);
|
|
85
|
+
if (!quiet) {
|
|
86
|
+
console.log(`Deleted: "${instance.FQN}"`);
|
|
87
|
+
}
|
|
47
88
|
}
|
|
48
89
|
catch (error) {
|
|
49
90
|
console.error(error);
|
|
50
91
|
throw error;
|
|
51
92
|
}
|
|
52
|
-
await stateStore.delete(resourceID);
|
|
53
93
|
}
|
|
54
|
-
|
|
94
|
+
(function (destroy) {
|
|
95
|
+
async function all(resources, options) {
|
|
96
|
+
if (options?.strategy !== "parallel") {
|
|
97
|
+
const sorted = resources.sort((a, b) => b.Seq - a.Seq);
|
|
98
|
+
for (const resource of sorted) {
|
|
99
|
+
await destroy(resource);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
await Promise.all(resources.map((resource) => destroy(resource, options)));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
destroy.all = all;
|
|
107
|
+
async function sequentially(...resources) {
|
|
108
|
+
for (const resource of resources) {
|
|
109
|
+
if (resource) {
|
|
110
|
+
await destroy(resource);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
destroy.sequentially = sequentially;
|
|
115
|
+
})(destroy || (destroy = {}));
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import * as esbuild from "esbuild";
|
|
2
|
+
import type { Context } from "../context";
|
|
3
|
+
import { Resource } from "../resource";
|
|
2
4
|
export interface BundleProps {
|
|
3
5
|
/**
|
|
4
6
|
* Entry point for the bundle
|
|
@@ -41,7 +43,7 @@ export interface BundleProps {
|
|
|
41
43
|
*/
|
|
42
44
|
options?: Partial<esbuild.BuildOptions>;
|
|
43
45
|
}
|
|
44
|
-
export interface
|
|
46
|
+
export interface Bundle extends Resource<"esbuild::Bundle"> {
|
|
45
47
|
/**
|
|
46
48
|
* Path to the bundled file
|
|
47
49
|
*/
|
|
@@ -51,21 +53,7 @@ export interface BundleOutput {
|
|
|
51
53
|
*/
|
|
52
54
|
hash: string;
|
|
53
55
|
}
|
|
54
|
-
declare const
|
|
55
|
-
export declare class Bundle extends Bundle_base {
|
|
56
|
-
/**
|
|
57
|
-
* Get the metafile from the last build
|
|
58
|
-
*/
|
|
59
|
-
getMetafile(ctx: {
|
|
60
|
-
get<T>(key: string): Promise<T | undefined>;
|
|
61
|
-
}): Promise<esbuild.Metafile | undefined>;
|
|
62
|
-
/**
|
|
63
|
-
* Get the hash from the last build
|
|
64
|
-
*/
|
|
65
|
-
getHash(ctx: {
|
|
66
|
-
get<T>(key: string): Promise<T | undefined>;
|
|
67
|
-
}): Promise<string | undefined>;
|
|
68
|
-
}
|
|
56
|
+
export declare const Bundle: ((this: Context<Bundle>, id: string, props: BundleProps) => Promise<Bundle>) | (((this: any, id: string, props: BundleProps) => never) & (new (_: never) => never));
|
|
69
57
|
export declare function bundle(props: BundleProps): Promise<esbuild.BuildResult<{
|
|
70
58
|
bundle: boolean;
|
|
71
59
|
splitting?: boolean;
|
|
@@ -148,5 +136,3 @@ export declare function bundle(props: BundleProps): Promise<esbuild.BuildResult<
|
|
|
148
136
|
logOverride?: Record<string, esbuild.LogLevel>;
|
|
149
137
|
tsconfigRaw?: string | esbuild.TsconfigRaw;
|
|
150
138
|
}>>;
|
|
151
|
-
export {};
|
|
152
|
-
//# sourceMappingURL=esbuild.d.ts.map
|
|
@@ -2,46 +2,33 @@ import * as esbuild from "esbuild";
|
|
|
2
2
|
import crypto from "node:crypto";
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
|
-
import { Resource } from "
|
|
6
|
-
export
|
|
5
|
+
import { Resource } from "../resource";
|
|
6
|
+
export const Bundle = Resource("esbuild::Bundle", {
|
|
7
7
|
alwaysUpdate: true,
|
|
8
|
-
}, async (
|
|
8
|
+
}, async function (id, props) {
|
|
9
9
|
// Determine output path
|
|
10
10
|
const outputPath = getOutputPath(props);
|
|
11
11
|
// Ensure output directory exists
|
|
12
12
|
await fs.promises.mkdir(path.dirname(outputPath), { recursive: true });
|
|
13
|
-
if (
|
|
13
|
+
if (this.phase === "delete") {
|
|
14
14
|
await fs.promises.unlink(outputPath).catch(() => { });
|
|
15
15
|
// Also clean up sourcemap if it exists
|
|
16
16
|
await fs.promises.unlink(outputPath + ".map").catch(() => { });
|
|
17
|
-
return
|
|
17
|
+
return this.destroy();
|
|
18
18
|
}
|
|
19
19
|
const result = await bundle(props);
|
|
20
20
|
// Calculate hash of the output
|
|
21
21
|
const contents = await fs.promises.readFile(outputPath);
|
|
22
22
|
const hash = crypto.createHash("sha256").update(contents).digest("hex");
|
|
23
23
|
// Store metadata in context
|
|
24
|
-
await
|
|
25
|
-
await
|
|
24
|
+
await this.set("metafile", result.metafile);
|
|
25
|
+
await this.set("hash", hash);
|
|
26
26
|
// Return output info
|
|
27
|
-
return {
|
|
27
|
+
return this({
|
|
28
28
|
path: outputPath,
|
|
29
29
|
hash,
|
|
30
|
-
};
|
|
31
|
-
})
|
|
32
|
-
/**
|
|
33
|
-
* Get the metafile from the last build
|
|
34
|
-
*/
|
|
35
|
-
async getMetafile(ctx) {
|
|
36
|
-
return ctx.get("metafile");
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Get the hash from the last build
|
|
40
|
-
*/
|
|
41
|
-
async getHash(ctx) {
|
|
42
|
-
return ctx.get("hash");
|
|
43
|
-
}
|
|
44
|
-
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
45
32
|
export async function bundle(props) {
|
|
46
33
|
const outputPath = getOutputPath(props);
|
|
47
34
|
// Build the bundle
|
|
@@ -64,4 +51,3 @@ function getOutputPath(props) {
|
|
|
64
51
|
return (props.outfile ||
|
|
65
52
|
path.join(props.outdir || "dist", path.basename(props.entryPoint, path.extname(props.entryPoint)) + ".js"));
|
|
66
53
|
}
|
|
67
|
-
//# sourceMappingURL=esbuild.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./bundle";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./bundle";
|
package/lib/fs/file.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Context } from "../context";
|
|
2
|
+
import { Resource } from "../resource";
|
|
3
|
+
export interface File extends Resource<"fs::File"> {
|
|
4
|
+
path: string;
|
|
5
|
+
content: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const File: ((this: Context<File>, id: string, { path: filePath, content, }: {
|
|
8
|
+
path: string;
|
|
9
|
+
content: string;
|
|
10
|
+
}) => Promise<File>) | (((this: any, id: string, props: {
|
|
11
|
+
path: string;
|
|
12
|
+
content: string;
|
|
13
|
+
}) => never) & (new (_: never) => never));
|
package/lib/fs/file.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { Resource } from "../resource";
|
|
4
|
+
import { ignore } from "../util/ignore";
|
|
5
|
+
export const File = Resource("fs::File", async function (id, { path: filePath, content, }) {
|
|
6
|
+
if (this.phase === "delete") {
|
|
7
|
+
await ignore("ENOENT", async () => fs.promises.unlink(filePath));
|
|
8
|
+
return this.destroy();
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
await fs.promises.mkdir(path.dirname(filePath), {
|
|
12
|
+
recursive: true,
|
|
13
|
+
});
|
|
14
|
+
await fs.promises.writeFile(filePath, content);
|
|
15
|
+
}
|
|
16
|
+
return this({
|
|
17
|
+
path: filePath,
|
|
18
|
+
content,
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Context } from "../context";
|
|
2
|
+
import { Resource } from "../resource";
|
|
3
|
+
export interface Folder extends Resource<"fs::Folder"> {
|
|
4
|
+
path: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const Folder: ((this: Context<Folder>, id: string, { path: dirPath }: {
|
|
7
|
+
path: string;
|
|
8
|
+
}) => Promise<Folder>) | (((this: any, id: string, props: {
|
|
9
|
+
path: string;
|
|
10
|
+
}) => never) & (new (_: never) => never));
|
package/lib/fs/folder.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { Resource } from "../resource";
|
|
3
|
+
import { ignore } from "../util/ignore";
|
|
4
|
+
export const Folder = Resource("fs::Folder", async function (id, { path: dirPath }) {
|
|
5
|
+
if (this.phase === "delete") {
|
|
6
|
+
// we just do a best effort attempt
|
|
7
|
+
await ignore(["ENOENT", "ENOTEMPTY"], async () => fs.promises.rmdir(dirPath));
|
|
8
|
+
return this.destroy();
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
await ignore("EEXIST", async () => fs.promises.mkdir(dirPath, { recursive: true }));
|
|
12
|
+
}
|
|
13
|
+
return this({
|
|
14
|
+
path: dirPath,
|
|
15
|
+
});
|
|
16
|
+
});
|
package/lib/fs/index.js
ADDED
package/lib/github/client.d.ts
CHANGED
package/lib/github/client.js
CHANGED
package/lib/github/index.d.ts
CHANGED
package/lib/github/index.js
CHANGED
package/lib/github/secret.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { Context } from "../context";
|
|
2
|
+
import { Resource } from "../resource";
|
|
1
3
|
import type { Secret } from "../secret";
|
|
2
4
|
/**
|
|
3
5
|
* Properties for creating or updating a GitHub Secret
|
|
@@ -27,7 +29,7 @@ export interface GitHubSecretProps {
|
|
|
27
29
|
/**
|
|
28
30
|
* Output returned after Secret creation/update
|
|
29
31
|
*/
|
|
30
|
-
export interface GitHubSecretOutput extends Omit<GitHubSecretProps, "value"> {
|
|
32
|
+
export interface GitHubSecretOutput extends Resource<"github::Secret">, Omit<GitHubSecretProps, "value"> {
|
|
31
33
|
/**
|
|
32
34
|
* The ID of the resource
|
|
33
35
|
*/
|
|
@@ -37,11 +39,7 @@ export interface GitHubSecretOutput extends Omit<GitHubSecretProps, "value"> {
|
|
|
37
39
|
*/
|
|
38
40
|
updatedAt: string;
|
|
39
41
|
}
|
|
40
|
-
declare const GitHubSecret_base: import("../resource").Provider<"github::Secret", [props: GitHubSecretProps], GitHubSecretOutput>;
|
|
41
42
|
/**
|
|
42
43
|
* Resource for managing GitHub repository secrets
|
|
43
44
|
*/
|
|
44
|
-
export declare
|
|
45
|
-
}
|
|
46
|
-
export {};
|
|
47
|
-
//# sourceMappingURL=secret.d.ts.map
|
|
45
|
+
export declare const GitHubSecret: ((this: Context<GitHubSecretOutput>, id: string, props: GitHubSecretProps) => Promise<GitHubSecretOutput>) | (((this: any, id: string, props: GitHubSecretProps) => never) & (new (_: never) => never));
|
package/lib/github/secret.js
CHANGED
|
@@ -4,15 +4,16 @@ import { createGitHubClient, verifyGitHubAuth } from "./client";
|
|
|
4
4
|
/**
|
|
5
5
|
* Resource for managing GitHub repository secrets
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
7
|
+
export const GitHubSecret = Resource("github::Secret", async function (id, props) {
|
|
8
8
|
// Create authenticated Octokit client - will automatically handle token resolution
|
|
9
|
+
/// TODO: use fetch
|
|
9
10
|
const octokit = await createGitHubClient({ token: props.token });
|
|
10
11
|
// Verify authentication and permissions
|
|
11
|
-
if (!
|
|
12
|
+
if (!this.quiet) {
|
|
12
13
|
await verifyGitHubAuth(octokit, props.owner, props.repository);
|
|
13
14
|
}
|
|
14
|
-
if (
|
|
15
|
-
if (
|
|
15
|
+
if (this.phase === "delete") {
|
|
16
|
+
if (this.output?.id) {
|
|
16
17
|
try {
|
|
17
18
|
// Delete the secret
|
|
18
19
|
await octokit.rest.actions.deleteRepoSecret({
|
|
@@ -32,7 +33,7 @@ export class GitHubSecret extends Resource("github::Secret", async (ctx, props)
|
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
35
|
// Return void (a deleted resource has no content)
|
|
35
|
-
return
|
|
36
|
+
return this.destroy();
|
|
36
37
|
}
|
|
37
38
|
else {
|
|
38
39
|
try {
|
|
@@ -44,7 +45,7 @@ export class GitHubSecret extends Resource("github::Secret", async (ctx, props)
|
|
|
44
45
|
// Encrypt the secret value using libsodium
|
|
45
46
|
const encryptedValue = await encryptString(props.value.unencrypted, publicKey.key);
|
|
46
47
|
// Create or update the secret with the encrypted value and key_id
|
|
47
|
-
|
|
48
|
+
await octokit.rest.actions.createOrUpdateRepoSecret({
|
|
48
49
|
owner: props.owner,
|
|
49
50
|
repo: props.repository,
|
|
50
51
|
secret_name: props.name,
|
|
@@ -52,15 +53,14 @@ export class GitHubSecret extends Resource("github::Secret", async (ctx, props)
|
|
|
52
53
|
key_id: publicKey.key_id,
|
|
53
54
|
});
|
|
54
55
|
// GitHub doesn't return the secret details on create/update, so we need to construct it
|
|
55
|
-
|
|
56
|
+
return this({
|
|
56
57
|
id: `${props.owner}/${props.repository}/${props.name}`,
|
|
57
58
|
owner: props.owner,
|
|
58
59
|
repository: props.repository,
|
|
59
60
|
name: props.name,
|
|
60
61
|
token: props.token,
|
|
61
62
|
updatedAt: new Date().toISOString(),
|
|
62
|
-
};
|
|
63
|
-
return output;
|
|
63
|
+
});
|
|
64
64
|
}
|
|
65
65
|
catch (error) {
|
|
66
66
|
if (error.status === 403 &&
|
|
@@ -74,8 +74,7 @@ export class GitHubSecret extends Resource("github::Secret", async (ctx, props)
|
|
|
74
74
|
throw error;
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
|
-
})
|
|
78
|
-
}
|
|
77
|
+
});
|
|
79
78
|
/**
|
|
80
79
|
* Encrypt a value for GitHub using libsodium
|
|
81
80
|
* Based on GitHub's documentation for encrypting secrets
|
|
@@ -96,4 +95,3 @@ async function encryptString(value, publicKey) {
|
|
|
96
95
|
// Convert the encrypted message to base64
|
|
97
96
|
return sodium.to_base64(encryptedBin, sodium.base64_variants.ORIGINAL);
|
|
98
97
|
}
|
|
99
|
-
//# sourceMappingURL=secret.js.map
|
package/lib/index.d.ts
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
export * from "
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./error";
|
|
4
|
-
export * from "./global";
|
|
5
|
-
export * from "./input";
|
|
6
|
-
export * from "./output";
|
|
7
|
-
export * from "./print";
|
|
8
|
-
export { Resource, type Context, type CreateContext, type DeleteContext, type UpdateContext, } from "./resource";
|
|
1
|
+
export type * from "./context";
|
|
2
|
+
export * from "./resource";
|
|
9
3
|
export * from "./secret";
|
|
10
|
-
export
|
|
11
|
-
|
|
4
|
+
export * from "./state";
|
|
5
|
+
export * from "./util/ignore";
|
|
6
|
+
import { alchemy } from "./alchemy";
|
|
7
|
+
export default alchemy;
|
package/lib/index.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
export * from "
|
|
2
|
-
export * from "./alchemize";
|
|
3
|
-
export * from "./error";
|
|
4
|
-
export * from "./global";
|
|
5
|
-
export * from "./input";
|
|
6
|
-
export * from "./output";
|
|
7
|
-
export * from "./print";
|
|
8
|
-
export { Resource, } from "./resource";
|
|
1
|
+
export * from "./resource";
|
|
9
2
|
export * from "./secret";
|
|
10
|
-
|
|
3
|
+
export * from "./state";
|
|
4
|
+
export * from "./util/ignore";
|
|
5
|
+
import { alchemy } from "./alchemy";
|
|
6
|
+
export default alchemy;
|