alchemy 0.2.3 → 0.2.5
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/ai/ark.d.ts +11 -0
- package/lib/ai/ark.js +86 -0
- package/lib/ai/client.d.ts +51 -0
- package/lib/ai/client.js +29 -0
- package/lib/ai/data.d.ts +101 -0
- package/lib/ai/data.js +70 -0
- package/lib/ai/document.d.ts +101 -0
- package/lib/ai/document.js +82 -0
- package/lib/ai/index.d.ts +3 -0
- package/lib/ai/index.js +3 -0
- package/lib/alchemy.d.ts +83 -2
- package/lib/alchemy.js +31 -3
- package/lib/aws/bucket.d.ts +87 -1
- package/lib/aws/bucket.js +48 -1
- package/lib/aws/function.d.ts +186 -1
- package/lib/aws/function.js +62 -8
- package/lib/aws/oidc/github-oidc-provider.d.ts +81 -0
- package/lib/aws/oidc/github-oidc-provider.js +68 -0
- package/lib/aws/oidc/oidc-provider.d.ts +14 -6
- package/lib/aws/oidc/oidc-provider.js +26 -5
- package/lib/aws/policy-attachment.d.ts +44 -1
- package/lib/aws/policy-attachment.js +31 -0
- package/lib/aws/policy.d.ts +160 -1
- package/lib/aws/policy.js +78 -0
- package/lib/aws/queue.d.ts +83 -1
- package/lib/aws/queue.js +39 -0
- package/lib/aws/role.d.ts +162 -1
- package/lib/aws/role.js +114 -0
- package/lib/aws/ses.d.ts +57 -2
- package/lib/aws/ses.js +42 -1
- package/lib/aws/table.d.ts +96 -1
- package/lib/aws/table.js +36 -0
- package/lib/cloudflare/asset-manifest.js +0 -1
- package/lib/cloudflare/bound.js +0 -1
- package/lib/cloudflare/bucket.d.ts +37 -1
- package/lib/cloudflare/bucket.js +36 -0
- package/lib/cloudflare/durable-object-namespace.d.ts +25 -0
- package/lib/cloudflare/durable-object-namespace.js +22 -0
- package/lib/cloudflare/kv-namespace.d.ts +37 -1
- package/lib/cloudflare/kv-namespace.js +36 -0
- package/lib/cloudflare/static-site.d.ts +53 -1
- package/lib/cloudflare/static-site.js +53 -1
- package/lib/cloudflare/worker-metadata.js +0 -1
- package/lib/cloudflare/worker.d.ts +64 -1
- package/lib/cloudflare/worker.js +63 -0
- package/lib/cloudflare/wrangler.json.d.ts +1 -1
- package/lib/cloudflare/zone-settings.js +0 -1
- package/lib/cloudflare/zone.d.ts +56 -1
- package/lib/cloudflare/zone.js +55 -0
- package/lib/destroy.js +1 -1
- package/lib/esbuild/bundle.d.ts +43 -4
- package/lib/esbuild/bundle.js +16 -0
- package/lib/fs/file-collection.d.ts +16 -0
- package/lib/fs/file-collection.js +6 -0
- package/lib/fs/file-ref.d.ts +14 -0
- package/lib/fs/file-ref.js +6 -0
- package/lib/fs/file.d.ts +71 -25
- package/lib/fs/file.js +20 -44
- package/lib/fs/folder.d.ts +37 -5
- package/lib/fs/folder.js +26 -2
- package/lib/fs/index.d.ts +6 -0
- package/lib/fs/index.js +6 -0
- package/lib/fs/json-file.d.ts +16 -0
- package/lib/fs/json-file.js +7 -0
- package/lib/fs/text-file.d.ts +12 -0
- package/lib/fs/text-file.js +7 -0
- package/lib/fs/typescript-file.d.ts +19 -0
- package/lib/fs/typescript-file.js +14 -0
- package/lib/fs/yaml-file.d.ts +19 -0
- package/lib/fs/yaml-file.js +8 -0
- package/lib/github/secret.d.ts +63 -2
- package/lib/github/secret.js +61 -1
- package/lib/internal/docs.d.ts +5 -0
- package/lib/internal/docs.js +287 -0
- package/lib/resource.d.ts +1 -1
- package/lib/secret.d.ts +67 -0
- package/lib/secret.js +67 -0
- package/lib/shadcn/component.d.ts +1 -1
- package/lib/stripe/price.d.ts +51 -1
- package/lib/stripe/price.js +50 -0
- package/lib/stripe/product.d.ts +39 -1
- package/lib/stripe/product.js +38 -0
- package/lib/stripe/webhook.d.ts +46 -1
- package/lib/stripe/webhook.js +45 -0
- package/lib/test/bun.d.ts +64 -0
- package/lib/test/bun.js +35 -3
- package/lib/util/serde.js +14 -0
- package/lib/vite/vite.d.ts +1 -1
- package/lib/vitepress/dependencies.d.ts +2 -6
- package/lib/vitepress/vitepress.d.ts +12 -1
- package/lib/vitepress/vitepress.js +29 -23
- package/package.json +8 -3
- package/src/ai/ark.ts +118 -0
- package/src/ai/client.ts +78 -0
- package/src/ai/data.ts +149 -0
- package/src/ai/document.ts +165 -0
- package/src/ai/index.ts +3 -0
- package/src/alchemy.ts +88 -5
- package/src/aws/bucket.ts +111 -7
- package/src/aws/function.ts +231 -10
- package/src/aws/oidc/github-oidc-provider.ts +83 -0
- package/src/aws/oidc/oidc-provider.ts +39 -7
- package/src/aws/policy-attachment.ts +44 -1
- package/src/aws/policy.ts +177 -2
- package/src/aws/queue.ts +89 -0
- package/src/aws/role.ts +174 -2
- package/src/aws/ses.ts +56 -1
- package/src/aws/table.ts +103 -0
- package/src/cloudflare/bucket.ts +36 -0
- package/src/cloudflare/durable-object-namespace.ts +25 -0
- package/src/cloudflare/kv-namespace.ts +36 -0
- package/src/cloudflare/static-site.ts +53 -1
- package/src/cloudflare/worker.ts +63 -0
- package/src/cloudflare/zone.ts +55 -0
- package/src/destroy.ts +1 -1
- package/src/esbuild/bundle.ts +53 -3
- package/src/fs/file-collection.ts +24 -0
- package/src/fs/file-ref.ts +22 -0
- package/src/fs/file.ts +70 -77
- package/src/fs/folder.ts +44 -5
- package/src/fs/index.ts +6 -0
- package/src/fs/json-file.ts +23 -0
- package/src/fs/text-file.ts +19 -0
- package/src/fs/typescript-file.ts +36 -0
- package/src/fs/yaml-file.ts +26 -0
- package/src/github/secret.ts +65 -2
- package/src/internal/docs.ts +338 -0
- package/src/resource.ts +1 -1
- package/src/secret.ts +67 -0
- package/src/stripe/price.ts +50 -0
- package/src/stripe/product.ts +38 -0
- package/src/stripe/webhook.ts +45 -0
- package/src/test/bun.ts +83 -3
- package/src/util/serde.ts +17 -0
- package/src/vitepress/vitepress.ts +47 -26
- package/lib/docs/document.d.ts +0 -123
- package/lib/docs/document.js +0 -67
- package/lib/docs/index.d.ts +0 -1
- package/lib/docs/index.js +0 -1
- package/src/docs/document.ts +0 -225
- package/src/docs/index.ts +0 -1
package/lib/esbuild/bundle.d.ts
CHANGED
|
@@ -1,25 +1,35 @@
|
|
|
1
1
|
import * as esbuild from "esbuild";
|
|
2
2
|
import type { Context } from "../context";
|
|
3
3
|
import { Resource } from "../resource";
|
|
4
|
+
/**
|
|
5
|
+
* Properties for creating or updating an esbuild bundle
|
|
6
|
+
*/
|
|
4
7
|
export interface BundleProps {
|
|
5
8
|
/**
|
|
6
9
|
* Entry point for the bundle
|
|
10
|
+
* Path to the source file to bundle (e.g., "src/handler.ts")
|
|
7
11
|
*/
|
|
8
12
|
entryPoint: string;
|
|
9
13
|
/**
|
|
10
14
|
* Output directory for the bundle
|
|
15
|
+
* Directory where the bundled file will be written
|
|
11
16
|
*/
|
|
12
17
|
outdir?: string;
|
|
13
18
|
/**
|
|
14
19
|
* Output filename for the bundle
|
|
20
|
+
* Full path to the output file, overrides outdir if specified
|
|
15
21
|
*/
|
|
16
22
|
outfile?: string;
|
|
17
23
|
/**
|
|
18
|
-
* Bundle format
|
|
24
|
+
* Bundle format
|
|
25
|
+
* iife: Immediately Invoked Function Expression
|
|
26
|
+
* cjs: CommonJS
|
|
27
|
+
* esm: ECMAScript Modules
|
|
19
28
|
*/
|
|
20
29
|
format?: "iife" | "cjs" | "esm";
|
|
21
30
|
/**
|
|
22
|
-
* Target environment
|
|
31
|
+
* Target environment
|
|
32
|
+
* Examples: 'node16', 'node18', 'es2020'
|
|
23
33
|
*/
|
|
24
34
|
target?: string | string[];
|
|
25
35
|
/**
|
|
@@ -28,32 +38,61 @@ export interface BundleProps {
|
|
|
28
38
|
minify?: boolean;
|
|
29
39
|
/**
|
|
30
40
|
* Whether to generate sourcemaps
|
|
41
|
+
* inline: Include sourcemap in bundle
|
|
42
|
+
* external: Generate separate .map file
|
|
43
|
+
* both: Generate both inline and external
|
|
31
44
|
*/
|
|
32
45
|
sourcemap?: boolean | "inline" | "external" | "both";
|
|
33
46
|
/**
|
|
34
47
|
* External packages to exclude from bundle
|
|
48
|
+
* Array of package names to mark as external
|
|
35
49
|
*/
|
|
36
50
|
external?: string[];
|
|
37
51
|
/**
|
|
38
|
-
* Platform to target
|
|
52
|
+
* Platform to target
|
|
53
|
+
* browser: Browser environment
|
|
54
|
+
* node: Node.js environment
|
|
55
|
+
* neutral: Platform-agnostic
|
|
39
56
|
*/
|
|
40
57
|
platform?: "browser" | "node" | "neutral";
|
|
41
58
|
/**
|
|
42
59
|
* Additional esbuild options
|
|
60
|
+
* Any other valid esbuild BuildOptions
|
|
43
61
|
*/
|
|
44
62
|
options?: Partial<esbuild.BuildOptions>;
|
|
45
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Output returned after bundle creation/update
|
|
66
|
+
*/
|
|
46
67
|
export interface Bundle extends Resource<"esbuild::Bundle"> {
|
|
47
68
|
/**
|
|
48
69
|
* Path to the bundled file
|
|
70
|
+
* Absolute or relative path to the generated bundle
|
|
49
71
|
*/
|
|
50
72
|
path: string;
|
|
51
73
|
/**
|
|
52
74
|
* SHA-256 hash of the bundle contents
|
|
75
|
+
* Used for cache busting and content verification
|
|
53
76
|
*/
|
|
54
77
|
hash: string;
|
|
55
78
|
}
|
|
56
|
-
|
|
79
|
+
/**
|
|
80
|
+
* esbuild Bundle Resource
|
|
81
|
+
*
|
|
82
|
+
* Creates and manages bundled JavaScript/TypeScript files using esbuild.
|
|
83
|
+
* Supports various output formats, sourcemaps, and platform targets.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* // Bundle a TypeScript file for Node.js
|
|
87
|
+
* const bundle = await Bundle("handler", {
|
|
88
|
+
* entryPoint: "src/handler.ts",
|
|
89
|
+
* outdir: ".alchemy/.out",
|
|
90
|
+
* format: "esm",
|
|
91
|
+
* platform: "node",
|
|
92
|
+
* target: "node18"
|
|
93
|
+
* });
|
|
94
|
+
*/
|
|
95
|
+
export declare const Bundle: (((this: any, id: string, props?: {}) => never) & (new (_: never) => never)) | ((this: Context<Bundle>, id: string, props: BundleProps) => Promise<Bundle>);
|
|
57
96
|
export declare function bundle(props: BundleProps): Promise<esbuild.BuildResult<{
|
|
58
97
|
bundle: boolean;
|
|
59
98
|
splitting?: boolean;
|
package/lib/esbuild/bundle.js
CHANGED
|
@@ -3,6 +3,22 @@ import crypto from "node:crypto";
|
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { Resource } from "../resource";
|
|
6
|
+
/**
|
|
7
|
+
* esbuild Bundle Resource
|
|
8
|
+
*
|
|
9
|
+
* Creates and manages bundled JavaScript/TypeScript files using esbuild.
|
|
10
|
+
* Supports various output formats, sourcemaps, and platform targets.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // Bundle a TypeScript file for Node.js
|
|
14
|
+
* const bundle = await Bundle("handler", {
|
|
15
|
+
* entryPoint: "src/handler.ts",
|
|
16
|
+
* outdir: ".alchemy/.out",
|
|
17
|
+
* format: "esm",
|
|
18
|
+
* platform: "node",
|
|
19
|
+
* target: "node18"
|
|
20
|
+
* });
|
|
21
|
+
*/
|
|
6
22
|
export const Bundle = Resource("esbuild::Bundle", {
|
|
7
23
|
alwaysUpdate: true,
|
|
8
24
|
}, async function (id, props) {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Collection of files with their contents
|
|
3
|
+
*/
|
|
4
|
+
export type FileCollection = {
|
|
5
|
+
/**
|
|
6
|
+
* Type identifier for FileCollection
|
|
7
|
+
*/
|
|
8
|
+
type: "fs::FileCollection";
|
|
9
|
+
/**
|
|
10
|
+
* Map of relative paths to file contents
|
|
11
|
+
*/
|
|
12
|
+
files: {
|
|
13
|
+
[relativePath: string]: string;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export declare function isFileCollection(value: unknown): value is FileCollection;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reference to a file in the filesystem
|
|
3
|
+
*/
|
|
4
|
+
export type FileRef = {
|
|
5
|
+
/**
|
|
6
|
+
* Type identifier for FileRef
|
|
7
|
+
*/
|
|
8
|
+
kind: "fs::FileRef";
|
|
9
|
+
/**
|
|
10
|
+
* Path to the file
|
|
11
|
+
*/
|
|
12
|
+
path: string;
|
|
13
|
+
};
|
|
14
|
+
export declare function isFileRef(value: unknown): value is FileRef;
|
package/lib/fs/file.d.ts
CHANGED
|
@@ -1,40 +1,86 @@
|
|
|
1
1
|
import type { Context } from "../context";
|
|
2
2
|
import { Resource } from "../resource";
|
|
3
|
+
import type { FileCollection } from "./file-collection";
|
|
4
|
+
import type { FileRef } from "./file-ref";
|
|
3
5
|
declare module "../alchemy" {
|
|
4
6
|
interface Alchemy {
|
|
7
|
+
/**
|
|
8
|
+
* Creates a reference to a file in the filesystem.
|
|
9
|
+
* Used in template string interpolation to include file contents,
|
|
10
|
+
* commonly for documentation generation.
|
|
11
|
+
*
|
|
12
|
+
* @param path Path to the file
|
|
13
|
+
* @returns Promise resolving to a FileRef
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // Include a file in documentation generation
|
|
17
|
+
* await Document("api-docs", {
|
|
18
|
+
* prompt: await alchemy`
|
|
19
|
+
* Generate docs using the contents of:
|
|
20
|
+
* ${alchemy.file("./README.md")}
|
|
21
|
+
* `
|
|
22
|
+
* });
|
|
23
|
+
*/
|
|
5
24
|
file(path: string): Promise<FileRef>;
|
|
25
|
+
/**
|
|
26
|
+
* Creates a collection of files with their contents.
|
|
27
|
+
* Used in template string interpolation to include multiple file contents,
|
|
28
|
+
* commonly for bulk documentation generation.
|
|
29
|
+
*
|
|
30
|
+
* @param paths Array of file paths to include in collection
|
|
31
|
+
* @returns Promise resolving to a FileCollection
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* // Include multiple source files in documentation generation
|
|
35
|
+
* await Document("provider-docs", {
|
|
36
|
+
* prompt: await alchemy`
|
|
37
|
+
* Generate comprehensive docs for these files:
|
|
38
|
+
* ${alchemy.files([
|
|
39
|
+
* "src/types.ts",
|
|
40
|
+
* "src/resource.ts",
|
|
41
|
+
* "src/provider.ts"
|
|
42
|
+
* ])}
|
|
43
|
+
* `
|
|
44
|
+
* });
|
|
45
|
+
*/
|
|
6
46
|
files(paths: string[]): Promise<FileCollection>;
|
|
7
47
|
files(path: string, ...paths: string[]): Promise<FileCollection>;
|
|
8
48
|
}
|
|
9
49
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
export declare function isFileRef(value: unknown): value is FileRef;
|
|
15
|
-
export type FileCollection = {
|
|
16
|
-
type: "fs::FileCollection";
|
|
17
|
-
files: {
|
|
18
|
-
[relativePath: string]: string;
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
export declare function isFileCollection(value: unknown): value is FileCollection;
|
|
50
|
+
/**
|
|
51
|
+
* Base file resource type
|
|
52
|
+
*/
|
|
22
53
|
export interface File extends Resource<"fs::File"> {
|
|
54
|
+
/**
|
|
55
|
+
* Path to the file
|
|
56
|
+
*/
|
|
23
57
|
path: string;
|
|
58
|
+
/**
|
|
59
|
+
* Content of the file
|
|
60
|
+
*/
|
|
24
61
|
content: string;
|
|
25
62
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
63
|
+
/**
|
|
64
|
+
* File Resource
|
|
65
|
+
*
|
|
66
|
+
* Creates and manages files in the filesystem with automatic directory creation
|
|
67
|
+
* and proper cleanup on deletion.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* // Create a simple text file
|
|
71
|
+
* const config = await File("config.txt", {
|
|
72
|
+
* path: "config.txt",
|
|
73
|
+
* content: "some configuration data"
|
|
74
|
+
* });
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* // Create a file in a nested directory
|
|
78
|
+
* const log = await File("logs/app.log", {
|
|
79
|
+
* path: "logs/app.log",
|
|
80
|
+
* content: "application log entry"
|
|
81
|
+
* });
|
|
82
|
+
*/
|
|
83
|
+
export declare const File: (((this: any, id: string, props?: {}) => never) & (new (_: never) => never)) | ((this: Context<File>, id: string, props: {
|
|
30
84
|
path: string;
|
|
31
85
|
content: string;
|
|
32
|
-
}
|
|
33
|
-
export type JsonFile = File;
|
|
34
|
-
export declare function JsonFile(id: string, content: any): Promise<JsonFile>;
|
|
35
|
-
export type TextFile = File;
|
|
36
|
-
export declare function TextFile(id: string, content: string): Promise<TextFile>;
|
|
37
|
-
export type YamlFile = File;
|
|
38
|
-
export declare function YamlFile(id: string, content: any): Promise<YamlFile>;
|
|
39
|
-
export type TypeScriptFile = File;
|
|
40
|
-
export declare function TypeScriptFile(id: string, content: string): Promise<TypeScriptFile>;
|
|
86
|
+
}) => Promise<File>);
|
package/lib/fs/file.js
CHANGED
|
@@ -3,18 +3,6 @@ import path from "node:path";
|
|
|
3
3
|
import { Resource } from "../resource";
|
|
4
4
|
import { ignore } from "../util/ignore";
|
|
5
5
|
import { alchemy } from "../alchemy";
|
|
6
|
-
export function isFileRef(value) {
|
|
7
|
-
return (typeof value === "object" &&
|
|
8
|
-
value !== null &&
|
|
9
|
-
"kind" in value &&
|
|
10
|
-
value.kind === "fs::FileRef");
|
|
11
|
-
}
|
|
12
|
-
export function isFileCollection(value) {
|
|
13
|
-
return (typeof value === "object" &&
|
|
14
|
-
value !== null &&
|
|
15
|
-
"type" in value &&
|
|
16
|
-
value.type === "fs::FileCollection");
|
|
17
|
-
}
|
|
18
6
|
alchemy.file = async (path) => ({
|
|
19
7
|
kind: "fs::FileRef",
|
|
20
8
|
path,
|
|
@@ -29,6 +17,26 @@ alchemy.files = async (...args) => {
|
|
|
29
17
|
]))),
|
|
30
18
|
};
|
|
31
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* File Resource
|
|
22
|
+
*
|
|
23
|
+
* Creates and manages files in the filesystem with automatic directory creation
|
|
24
|
+
* and proper cleanup on deletion.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* // Create a simple text file
|
|
28
|
+
* const config = await File("config.txt", {
|
|
29
|
+
* path: "config.txt",
|
|
30
|
+
* content: "some configuration data"
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* // Create a file in a nested directory
|
|
35
|
+
* const log = await File("logs/app.log", {
|
|
36
|
+
* path: "logs/app.log",
|
|
37
|
+
* content: "application log entry"
|
|
38
|
+
* });
|
|
39
|
+
*/
|
|
32
40
|
export const File = Resource("fs::File", async function (id, props) {
|
|
33
41
|
const filePath = props?.path ?? id;
|
|
34
42
|
if (this.phase === "delete") {
|
|
@@ -46,35 +54,3 @@ export const File = Resource("fs::File", async function (id, props) {
|
|
|
46
54
|
content: props.content,
|
|
47
55
|
});
|
|
48
56
|
});
|
|
49
|
-
export function JsonFile(id, content) {
|
|
50
|
-
return File(id, {
|
|
51
|
-
path: id,
|
|
52
|
-
content: JSON.stringify(content, null, 2),
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
export function TextFile(id, content) {
|
|
56
|
-
return File(id, {
|
|
57
|
-
path: id,
|
|
58
|
-
content,
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
export async function YamlFile(id, content) {
|
|
62
|
-
const yaml = await import("yaml");
|
|
63
|
-
return File(id, {
|
|
64
|
-
path: id,
|
|
65
|
-
content: yaml.stringify(content),
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
export async function TypeScriptFile(id, content) {
|
|
69
|
-
const prettier = await import("prettier");
|
|
70
|
-
return File(id, {
|
|
71
|
-
path: id,
|
|
72
|
-
content: await prettier.format(content, {
|
|
73
|
-
parser: "typescript",
|
|
74
|
-
editor: {
|
|
75
|
-
tabWidth: 2,
|
|
76
|
-
indentWidth: 2,
|
|
77
|
-
},
|
|
78
|
-
}),
|
|
79
|
-
});
|
|
80
|
-
}
|
package/lib/fs/folder.d.ts
CHANGED
|
@@ -1,10 +1,42 @@
|
|
|
1
1
|
import type { Context } from "../context";
|
|
2
2
|
import { Resource } from "../resource";
|
|
3
|
+
export interface FolderProps {
|
|
4
|
+
/**
|
|
5
|
+
* The path of the folder
|
|
6
|
+
*/
|
|
7
|
+
path?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Whether to delete the folder during the delete phase
|
|
10
|
+
* @default true
|
|
11
|
+
*/
|
|
12
|
+
delete?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Base folder resource type
|
|
16
|
+
*/
|
|
3
17
|
export interface Folder extends Resource<"fs::Folder"> {
|
|
4
18
|
path: string;
|
|
5
19
|
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Folder Resource
|
|
22
|
+
*
|
|
23
|
+
* Creates and manages directories in the filesystem with automatic parent
|
|
24
|
+
* directory creation and cleanup on deletion.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* // Create a directory using id as path
|
|
28
|
+
* const dir = await Folder("uploads");
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* // Create a directory with explicit path
|
|
32
|
+
* const dir = await Folder("uploads", {
|
|
33
|
+
* path: "uploads"
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* // Create a nested directory structure
|
|
38
|
+
* const logs = await Folder("var/log/app", {
|
|
39
|
+
* path: "var/log/app"
|
|
40
|
+
* });
|
|
41
|
+
*/
|
|
42
|
+
export declare const Folder: (((this: any, id: string, props?: {}) => never) & (new (_: never) => never)) | ((this: Context<Folder>, id: string, props?: FolderProps) => Promise<Folder>);
|
package/lib/fs/folder.js
CHANGED
|
@@ -1,11 +1,35 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import { Resource } from "../resource";
|
|
3
3
|
import { ignore } from "../util/ignore";
|
|
4
|
+
/**
|
|
5
|
+
* Folder Resource
|
|
6
|
+
*
|
|
7
|
+
* Creates and manages directories in the filesystem with automatic parent
|
|
8
|
+
* directory creation and cleanup on deletion.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // Create a directory using id as path
|
|
12
|
+
* const dir = await Folder("uploads");
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // Create a directory with explicit path
|
|
16
|
+
* const dir = await Folder("uploads", {
|
|
17
|
+
* path: "uploads"
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // Create a nested directory structure
|
|
22
|
+
* const logs = await Folder("var/log/app", {
|
|
23
|
+
* path: "var/log/app"
|
|
24
|
+
* });
|
|
25
|
+
*/
|
|
4
26
|
export const Folder = Resource("fs::Folder", async function (id, props) {
|
|
5
27
|
const dirPath = props?.path ?? id;
|
|
6
28
|
if (this.phase === "delete") {
|
|
7
|
-
|
|
8
|
-
|
|
29
|
+
if (props?.delete !== false) {
|
|
30
|
+
// we just do a best effort attempt
|
|
31
|
+
await ignore(["ENOENT", "ENOTEMPTY"], async () => fs.promises.rmdir(dirPath));
|
|
32
|
+
}
|
|
9
33
|
return this.destroy();
|
|
10
34
|
}
|
|
11
35
|
else {
|
package/lib/fs/index.d.ts
CHANGED
package/lib/fs/index.js
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { File } from "./file";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a JSON file with formatted content
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* // Create a JSON configuration file
|
|
7
|
+
* const config = await JsonFile("config.json", {
|
|
8
|
+
* api: {
|
|
9
|
+
* endpoint: "https://api.example.com",
|
|
10
|
+
* version: "v1"
|
|
11
|
+
* },
|
|
12
|
+
* features: ["auth", "logging"]
|
|
13
|
+
* });
|
|
14
|
+
*/
|
|
15
|
+
export type JsonFile = File;
|
|
16
|
+
export declare function JsonFile(id: string, content: any): Promise<JsonFile>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { File } from "./file";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a plain text file
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* // Create a text file with content
|
|
7
|
+
* const readme = await TextFile("README.md",
|
|
8
|
+
* "# Project Name\n\nProject description goes here."
|
|
9
|
+
* );
|
|
10
|
+
*/
|
|
11
|
+
export type TextFile = File;
|
|
12
|
+
export declare function TextFile(id: string, content: string): Promise<TextFile>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { File } from "./file";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a TypeScript file with formatted content using prettier
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* // Create a TypeScript file
|
|
7
|
+
* const component = await TypeScriptFile("Component.ts", `
|
|
8
|
+
* interface Props {
|
|
9
|
+
* name: string;
|
|
10
|
+
* age: number;
|
|
11
|
+
* }
|
|
12
|
+
*
|
|
13
|
+
* export function Component({ name, age }: Props) {
|
|
14
|
+
* return <div>Hello {name}, you are {age} years old</div>;
|
|
15
|
+
* }
|
|
16
|
+
* `);
|
|
17
|
+
*/
|
|
18
|
+
export type TypeScriptFile = File;
|
|
19
|
+
export declare function TypeScriptFile(id: string, content: string): Promise<TypeScriptFile>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { File } from "./file";
|
|
2
|
+
export async function TypeScriptFile(id, content) {
|
|
3
|
+
const prettier = await import("prettier");
|
|
4
|
+
return File(id, {
|
|
5
|
+
path: id,
|
|
6
|
+
content: await prettier.format(content, {
|
|
7
|
+
parser: "typescript",
|
|
8
|
+
editor: {
|
|
9
|
+
tabWidth: 2,
|
|
10
|
+
indentWidth: 2,
|
|
11
|
+
},
|
|
12
|
+
}),
|
|
13
|
+
});
|
|
14
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { File } from "./file";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a YAML file with formatted content
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* // Create a YAML configuration file
|
|
7
|
+
* const config = await YamlFile("config.yaml", {
|
|
8
|
+
* server:
|
|
9
|
+
* host: "localhost"
|
|
10
|
+
* port: 3000
|
|
11
|
+
* database:
|
|
12
|
+
* url: "postgresql://localhost:5432/db"
|
|
13
|
+
* pool:
|
|
14
|
+
* min: 1
|
|
15
|
+
* max: 10
|
|
16
|
+
* });
|
|
17
|
+
*/
|
|
18
|
+
export type YamlFile = File;
|
|
19
|
+
export declare function YamlFile(id: string, content: any): Promise<YamlFile>;
|
package/lib/github/secret.d.ts
CHANGED
|
@@ -23,8 +23,11 @@ export interface GitHubSecretProps {
|
|
|
23
23
|
value: Secret;
|
|
24
24
|
/**
|
|
25
25
|
* Optional GitHub API token (overrides environment variable)
|
|
26
|
+
* If not provided, will use GITHUB_TOKEN environment variable
|
|
27
|
+
* Token must have 'repo' scope for private repositories
|
|
28
|
+
* or 'public_repo' scope for public repositories
|
|
26
29
|
*/
|
|
27
|
-
token?:
|
|
30
|
+
token?: Secret;
|
|
28
31
|
}
|
|
29
32
|
/**
|
|
30
33
|
* Output returned after Secret creation/update
|
|
@@ -41,5 +44,63 @@ export interface GitHubSecretOutput extends Resource<"github::Secret">, Omit<Git
|
|
|
41
44
|
}
|
|
42
45
|
/**
|
|
43
46
|
* Resource for managing GitHub repository secrets
|
|
47
|
+
*
|
|
48
|
+
* Authentication is handled in the following order:
|
|
49
|
+
* 1. `token` parameter in the resource props (if provided)
|
|
50
|
+
* 2. `GITHUB_TOKEN` environment variable
|
|
51
|
+
*
|
|
52
|
+
* The token must have the following permissions:
|
|
53
|
+
* - 'repo' scope for private repositories
|
|
54
|
+
* - 'public_repo' scope for public repositories
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* // Create a secret using GITHUB_TOKEN environment variable:
|
|
58
|
+
* const secret = await GitHubSecret("my-secret", {
|
|
59
|
+
* owner: "my-github-username",
|
|
60
|
+
* repository: "my-repo",
|
|
61
|
+
* name: "API_KEY",
|
|
62
|
+
* value: alchemy.secret("my-secret-value")
|
|
63
|
+
* });
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* // Create a secret with a custom GitHub token:
|
|
67
|
+
* const secret = await GitHubSecret("my-secret", {
|
|
68
|
+
* owner: "my-github-username",
|
|
69
|
+
* repository: "my-repo",
|
|
70
|
+
* name: "API_KEY",
|
|
71
|
+
* value: alchemy.secret("my-secret-value"),
|
|
72
|
+
* token: alchemy.secret(process.env.CUSTOM_GITHUB_TOKEN)
|
|
73
|
+
* });
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* // Create multiple secrets with environment variables:
|
|
77
|
+
* const secrets = await Promise.all([
|
|
78
|
+
* GitHubSecret("aws-secret", {
|
|
79
|
+
* owner: "my-github-username",
|
|
80
|
+
* repository: "cloud-app",
|
|
81
|
+
* name: "AWS_ROLE_ARN",
|
|
82
|
+
* value: alchemy.secret(process.env.AWS_ROLE_ARN)
|
|
83
|
+
* }),
|
|
84
|
+
* GitHubSecret("cf-secret", {
|
|
85
|
+
* owner: "my-github-username",
|
|
86
|
+
* repository: "cloud-app",
|
|
87
|
+
* name: "CLOUDFLARE_API_KEY",
|
|
88
|
+
* value: alchemy.secret(process.env.CLOUDFLARE_API_KEY)
|
|
89
|
+
* })
|
|
90
|
+
* ]);
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* // Create a secret in a secure scope with a password:
|
|
94
|
+
* await alchemy.run("secure-scope", {
|
|
95
|
+
* password: process.env.SECRET_PASSPHRASE
|
|
96
|
+
* }, async () => {
|
|
97
|
+
* const secret = await GitHubSecret("deploy-secret", {
|
|
98
|
+
* owner: "my-github-username",
|
|
99
|
+
* repository: "my-app",
|
|
100
|
+
* name: "DEPLOY_TOKEN",
|
|
101
|
+
* value: alchemy.secret(process.env.DEPLOY_TOKEN),
|
|
102
|
+
* token: alchemy.secret(process.env.GITHUB_TOKEN)
|
|
103
|
+
* });
|
|
104
|
+
* });
|
|
44
105
|
*/
|
|
45
|
-
export declare const GitHubSecret: ((this:
|
|
106
|
+
export declare const GitHubSecret: (((this: any, id: string, props?: {}) => never) & (new (_: never) => never)) | ((this: Context<GitHubSecretOutput>, id: string, props: GitHubSecretProps) => Promise<GitHubSecretOutput>);
|