alchemy 0.2.2 → 0.2.4
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/document.d.ts +97 -0
- package/lib/ai/document.js +82 -0
- package/lib/ai/index.d.ts +2 -0
- package/lib/ai/index.js +2 -0
- package/lib/ai/object.d.ts +101 -0
- package/lib/ai/object.js +70 -0
- package/lib/alchemy.d.ts +84 -2
- package/lib/alchemy.js +114 -10
- package/lib/apply.d.ts +1 -1
- package/lib/apply.js +13 -10
- 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/context.d.ts +9 -4
- package/lib/context.js +4 -2
- package/lib/destroy.js +9 -8
- 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 +78 -5
- package/lib/fs/file.js +39 -3
- package/lib/fs/folder.d.ts +37 -5
- package/lib/fs/folder.js +28 -3
- 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 +324 -0
- package/lib/resource.d.ts +2 -2
- package/lib/resource.js +4 -0
- package/lib/scope.d.ts +1 -1
- package/lib/scope.js +6 -6
- package/lib/secret.d.ts +67 -0
- package/lib/secret.js +67 -0
- package/lib/shadcn/component.d.ts +1 -1
- package/lib/state.d.ts +1 -1
- package/lib/state.js +8 -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.d.ts +3 -1
- package/lib/util/serde.js +20 -4
- package/lib/vite/vite.d.ts +1 -1
- package/lib/vitepress/dependencies.d.ts +12 -0
- package/lib/vitepress/dependencies.js +35 -0
- package/lib/vitepress/home-page.d.ts +133 -0
- package/lib/vitepress/home-page.js +11 -0
- package/lib/vitepress/index.d.ts +2 -0
- package/lib/vitepress/index.js +2 -0
- package/lib/vitepress/vitepress.d.ts +71 -0
- package/lib/vitepress/vitepress.js +266 -0
- package/package.json +22 -10
- package/src/ai/ark.ts +118 -0
- package/src/ai/client.ts +78 -0
- package/src/ai/document.ts +160 -0
- package/src/ai/index.ts +2 -0
- package/src/ai/object.ts +149 -0
- package/src/alchemy.ts +192 -17
- package/src/apply.ts +25 -13
- 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/context.ts +30 -10
- package/src/destroy.ts +11 -8
- 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 +107 -6
- package/src/fs/folder.ts +45 -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 +369 -0
- package/src/resource.ts +7 -2
- package/src/scope.ts +9 -9
- package/src/secret.ts +67 -0
- package/src/state.ts +9 -2
- 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 +30 -4
- package/src/vitepress/dependencies.ts +68 -0
- package/src/vitepress/home-page.ts +166 -0
- package/src/vitepress/index.md +75 -0
- package/src/vitepress/index.ts +2 -0
- package/src/vitepress/vitepress.ts +382 -0
- package/lib/project/vite.d.ts +0 -90
- package/lib/project/vite.js +0 -228
- package/src/project/vite.ts +0 -406
package/src/aws/table.ts
CHANGED
|
@@ -13,28 +13,131 @@ import { Resource } from "../resource";
|
|
|
13
13
|
import { ignore } from "../util/ignore";
|
|
14
14
|
import { withExponentialBackoff } from "../util/retry";
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Properties for creating or updating a DynamoDB table
|
|
18
|
+
*/
|
|
16
19
|
export interface TableProps {
|
|
20
|
+
/**
|
|
21
|
+
* Name of the DynamoDB table
|
|
22
|
+
*/
|
|
17
23
|
tableName: string;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Primary partition key (hash key) configuration
|
|
27
|
+
* Defines the main identifier for items in the table
|
|
28
|
+
*/
|
|
18
29
|
partitionKey: {
|
|
30
|
+
/**
|
|
31
|
+
* Name of the partition key attribute
|
|
32
|
+
*/
|
|
19
33
|
name: string;
|
|
34
|
+
/**
|
|
35
|
+
* Data type of the partition key
|
|
36
|
+
* S: String, N: Number, B: Binary
|
|
37
|
+
*/
|
|
20
38
|
type: "S" | "N" | "B";
|
|
21
39
|
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Optional sort key (range key) configuration
|
|
43
|
+
* Used to sort items with the same partition key
|
|
44
|
+
*/
|
|
22
45
|
sortKey?: {
|
|
46
|
+
/**
|
|
47
|
+
* Name of the sort key attribute
|
|
48
|
+
*/
|
|
23
49
|
name: string;
|
|
50
|
+
/**
|
|
51
|
+
* Data type of the sort key
|
|
52
|
+
* S: String, N: Number, B: Binary
|
|
53
|
+
*/
|
|
24
54
|
type: "S" | "N" | "B";
|
|
25
55
|
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Billing mode for the table
|
|
59
|
+
* PROVISIONED: Set read/write capacity units
|
|
60
|
+
* PAY_PER_REQUEST: Pay per request pricing
|
|
61
|
+
*/
|
|
26
62
|
billingMode?: "PROVISIONED" | "PAY_PER_REQUEST";
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Read capacity units when using PROVISIONED billing mode
|
|
66
|
+
* Default: 5
|
|
67
|
+
*/
|
|
27
68
|
readCapacity?: number;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Write capacity units when using PROVISIONED billing mode
|
|
72
|
+
* Default: 5
|
|
73
|
+
*/
|
|
28
74
|
writeCapacity?: number;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Tags to apply to the table
|
|
78
|
+
* Key-value pairs for resource organization
|
|
79
|
+
*/
|
|
29
80
|
tags?: Record<string, string>;
|
|
30
81
|
}
|
|
31
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Output returned after DynamoDB table creation/update
|
|
85
|
+
*/
|
|
32
86
|
export interface Table extends Resource<"dynamo::Table">, TableProps {
|
|
87
|
+
/**
|
|
88
|
+
* ARN of the table
|
|
89
|
+
* Format: arn:aws:dynamodb:region:account-id:table/table-name
|
|
90
|
+
*/
|
|
33
91
|
arn: string;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* ARN of the table's stream if enabled
|
|
95
|
+
* Format: arn:aws:dynamodb:region:account-id:table/table-name/stream/timestamp
|
|
96
|
+
*/
|
|
34
97
|
streamArn?: string;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Unique identifier for the table
|
|
101
|
+
*/
|
|
35
102
|
tableId: string;
|
|
36
103
|
}
|
|
37
104
|
|
|
105
|
+
/**
|
|
106
|
+
* AWS DynamoDB Table Resource
|
|
107
|
+
*
|
|
108
|
+
* Creates and manages DynamoDB tables with support for partition and sort keys,
|
|
109
|
+
* flexible billing modes, and automatic table status monitoring.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* // Create a table with partition and sort key
|
|
113
|
+
* const table = await Table("user-events", {
|
|
114
|
+
* tableName: "user-events",
|
|
115
|
+
* partitionKey: {
|
|
116
|
+
* name: "id",
|
|
117
|
+
* type: "S"
|
|
118
|
+
* },
|
|
119
|
+
* sortKey: {
|
|
120
|
+
* name: "timestamp",
|
|
121
|
+
* type: "N"
|
|
122
|
+
* },
|
|
123
|
+
* tags: {
|
|
124
|
+
* Environment: "test"
|
|
125
|
+
* }
|
|
126
|
+
* });
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* // Create a table with provisioned capacity
|
|
130
|
+
* const table = await Table("high-throughput", {
|
|
131
|
+
* tableName: "high-throughput",
|
|
132
|
+
* partitionKey: {
|
|
133
|
+
* name: "userId",
|
|
134
|
+
* type: "S"
|
|
135
|
+
* },
|
|
136
|
+
* billingMode: "PROVISIONED",
|
|
137
|
+
* readCapacity: 100,
|
|
138
|
+
* writeCapacity: 50
|
|
139
|
+
* });
|
|
140
|
+
*/
|
|
38
141
|
export const Table = Resource(
|
|
39
142
|
"dynamo::Table",
|
|
40
143
|
async function (
|
package/src/cloudflare/bucket.ts
CHANGED
|
@@ -54,6 +54,42 @@ export interface R2Bucket
|
|
|
54
54
|
creationDate: number;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Creates and manages Cloudflare R2 Buckets for object storage.
|
|
59
|
+
*
|
|
60
|
+
* R2 Buckets provide S3-compatible object storage with automatic data replication
|
|
61
|
+
* across multiple regions for high availability and durability.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* // Create a basic R2 bucket with default settings
|
|
65
|
+
* const basicBucket = await R2Bucket("my-app-data", {
|
|
66
|
+
* name: "my-app-data"
|
|
67
|
+
* });
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* // Create a bucket with location hint for optimal performance
|
|
71
|
+
* const euBucket = await R2Bucket("eu-user-data", {
|
|
72
|
+
* name: "eu-user-data",
|
|
73
|
+
* locationHint: "eu",
|
|
74
|
+
* jurisdiction: "eu"
|
|
75
|
+
* });
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* // Create a development bucket with public access enabled
|
|
79
|
+
* const publicBucket = await R2Bucket("public-assets", {
|
|
80
|
+
* name: "public-assets",
|
|
81
|
+
* allowPublicAccess: true
|
|
82
|
+
* });
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* // Create a FedRAMP compliant bucket for government workloads
|
|
86
|
+
* const fedRampBucket = await R2Bucket("gov-data", {
|
|
87
|
+
* name: "gov-data",
|
|
88
|
+
* jurisdiction: "fedramp"
|
|
89
|
+
* });
|
|
90
|
+
*
|
|
91
|
+
* @see https://developers.cloudflare.com/r2/buckets/
|
|
92
|
+
*/
|
|
57
93
|
export const R2Bucket = Resource(
|
|
58
94
|
"cloudflare::R2Bucket",
|
|
59
95
|
async function (
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Properties for creating a Durable Object Namespace
|
|
3
|
+
*/
|
|
1
4
|
export interface DurableObjectNamespaceInput {
|
|
2
5
|
className: string;
|
|
3
6
|
scriptName?: string | undefined;
|
|
@@ -6,6 +9,28 @@ export interface DurableObjectNamespaceInput {
|
|
|
6
9
|
namespaceId?: string | undefined;
|
|
7
10
|
}
|
|
8
11
|
|
|
12
|
+
/**
|
|
13
|
+
* @example
|
|
14
|
+
* // Create a basic Durable Object namespace for stateful chat rooms
|
|
15
|
+
* const rooms = new DurableObjectNamespace("chat-rooms", {
|
|
16
|
+
* className: "ChatRoom"
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* // Create a Durable Object with SQLite storage for user data
|
|
21
|
+
* const users = new DurableObjectNamespace("user-store", {
|
|
22
|
+
* className: "User",
|
|
23
|
+
* sqlite: true
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* // Create a Durable Object in production for game state management
|
|
28
|
+
* const game = new DurableObjectNamespace("game-state", {
|
|
29
|
+
* className: "GameState",
|
|
30
|
+
* scriptName: "game-worker",
|
|
31
|
+
* environment: "production"
|
|
32
|
+
* });
|
|
33
|
+
*/
|
|
9
34
|
export class DurableObjectNamespace implements DurableObjectNamespaceInput {
|
|
10
35
|
public readonly type = "durable_object_namespace" as const;
|
|
11
36
|
// alias for bindingName to be consistent with other bindings
|
|
@@ -78,6 +78,42 @@ export interface KVNamespace
|
|
|
78
78
|
modifiedAt: number;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
+
/**
|
|
82
|
+
* A Cloudflare KV Namespace is a key-value store that can be used to store data for your application.
|
|
83
|
+
*
|
|
84
|
+
* @see https://developers.cloudflare.com/kv/concepts/kv-namespaces/
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* // Create a basic KV namespace for storing user data
|
|
88
|
+
* const users = await KVNamespace("users", {
|
|
89
|
+
* title: "user-data"
|
|
90
|
+
* });
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* // Create a KV namespace with initial values and TTL
|
|
94
|
+
* const sessions = await KVNamespace("sessions", {
|
|
95
|
+
* title: "user-sessions",
|
|
96
|
+
* values: [{
|
|
97
|
+
* key: "session_123",
|
|
98
|
+
* value: { userId: "user_456", role: "admin" },
|
|
99
|
+
* expirationTtl: 3600 // Expires in 1 hour
|
|
100
|
+
* }]
|
|
101
|
+
* });
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* // Create a KV namespace with metadata for caching
|
|
105
|
+
* const assets = await KVNamespace("assets", {
|
|
106
|
+
* title: "static-assets",
|
|
107
|
+
* values: [{
|
|
108
|
+
* key: "main.js",
|
|
109
|
+
* value: "content...",
|
|
110
|
+
* metadata: {
|
|
111
|
+
* contentType: "application/javascript",
|
|
112
|
+
* etag: "abc123"
|
|
113
|
+
* }
|
|
114
|
+
* }]
|
|
115
|
+
* });
|
|
116
|
+
*/
|
|
81
117
|
export const KVNamespace = Resource(
|
|
82
118
|
"cloudflare::KVNamespace",
|
|
83
119
|
async function (
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { exec } from "child_process";
|
|
2
2
|
import { promises as fs } from "fs";
|
|
3
|
-
import path from "path";
|
|
3
|
+
import path from "node:path";
|
|
4
4
|
import { promisify } from "util";
|
|
5
5
|
import type { Context } from "../context";
|
|
6
6
|
import type { BundleProps } from "../esbuild/bundle";
|
|
@@ -202,6 +202,58 @@ export interface StaticSite extends Resource<"cloudflare::StaticSite"> {
|
|
|
202
202
|
routes?: Record<string, string>;
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
+
/**
|
|
206
|
+
* A StaticSite resource deploys static web content to Cloudflare Workers, using KV for asset storage.
|
|
207
|
+
* It provides an efficient way to serve static websites with global distribution and caching.
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* // Create a basic static site with default settings
|
|
211
|
+
* const basicSite = await StaticSite("my-site", {
|
|
212
|
+
* name: "my-site",
|
|
213
|
+
* dir: "./dist",
|
|
214
|
+
* url: true
|
|
215
|
+
* });
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* // Create a static site with custom build command and minification disabled
|
|
219
|
+
* const devSite = await StaticSite("dev-site", {
|
|
220
|
+
* name: "dev-site",
|
|
221
|
+
* dir: "./public",
|
|
222
|
+
* build: {
|
|
223
|
+
* command: "npm run build"
|
|
224
|
+
* },
|
|
225
|
+
* bundle: {
|
|
226
|
+
* minify: false
|
|
227
|
+
* }
|
|
228
|
+
* });
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* // Create a static site with a backend API worker
|
|
232
|
+
* const backend = await Worker("api-backend", {
|
|
233
|
+
* name: "api-backend",
|
|
234
|
+
* entrypoint: "./src/api.ts"
|
|
235
|
+
* });
|
|
236
|
+
*
|
|
237
|
+
* const fullSite = await StaticSite("full-site", {
|
|
238
|
+
* name: "full-site",
|
|
239
|
+
* dir: "./dist",
|
|
240
|
+
* routes: {
|
|
241
|
+
* "/api/*": backend
|
|
242
|
+
* }
|
|
243
|
+
* });
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* // Create a static site with custom error page and index
|
|
247
|
+
* const customSite = await StaticSite("custom-site", {
|
|
248
|
+
* name: "custom-site",
|
|
249
|
+
* dir: "./www",
|
|
250
|
+
* errorPage: "404.html",
|
|
251
|
+
* indexPage: "home.html",
|
|
252
|
+
* domain: "www.example.com"
|
|
253
|
+
* });
|
|
254
|
+
*
|
|
255
|
+
* @see https://developers.cloudflare.com/workers/platform/sites
|
|
256
|
+
*/
|
|
205
257
|
export const StaticSite = Resource(
|
|
206
258
|
"cloudflare::StaticSite",
|
|
207
259
|
{
|
package/src/cloudflare/worker.ts
CHANGED
|
@@ -138,6 +138,69 @@ export interface Worker<B extends Bindings = Bindings>
|
|
|
138
138
|
};
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
+
/**
|
|
142
|
+
* A Cloudflare Worker is a serverless function that can be deployed to the Cloudflare network.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* // Create a basic HTTP handler worker with custom domain routing
|
|
146
|
+
* // and workers.dev URL:
|
|
147
|
+
* const api = await Worker("api", {
|
|
148
|
+
* name: "api-worker",
|
|
149
|
+
* entrypoint: "./src/api.ts",
|
|
150
|
+
* routes: ["api.example.com/*"],
|
|
151
|
+
* url: true
|
|
152
|
+
* });
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* // Create a real-time chat worker using Durable Objects
|
|
156
|
+
* // for state management:
|
|
157
|
+
* const chatRooms = new DurableObjectNamespace("chat-rooms");
|
|
158
|
+
* const userStore = new DurableObjectNamespace("user-store");
|
|
159
|
+
*
|
|
160
|
+
* const chat = await Worker("chat", {
|
|
161
|
+
* name: "chat-worker",
|
|
162
|
+
* entrypoint: "./src/chat.ts",
|
|
163
|
+
* bindings: {
|
|
164
|
+
* ROOMS: chatRooms,
|
|
165
|
+
* USERS: userStore
|
|
166
|
+
* },
|
|
167
|
+
* });
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* // Create a worker with KV namespace for caching and data storage:
|
|
171
|
+
* const cache = await KVNamespace("cache-store");
|
|
172
|
+
* const settings = await KVNamespace("user-settings");
|
|
173
|
+
*
|
|
174
|
+
* const cacheWorker = await Worker("cache", {
|
|
175
|
+
* name: "cache-worker",
|
|
176
|
+
* entrypoint: "./src/cache.ts",
|
|
177
|
+
* bindings: {
|
|
178
|
+
* CACHE: cache,
|
|
179
|
+
* SETTINGS: settings
|
|
180
|
+
* }
|
|
181
|
+
* });
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* // Create a worker with R2 bucket for object storage:
|
|
185
|
+
* const uploads = await R2Bucket("uploads", {
|
|
186
|
+
* name: "user-uploads"
|
|
187
|
+
* });
|
|
188
|
+
* const assets = await R2Bucket("assets", {
|
|
189
|
+
* name: "static-assets",
|
|
190
|
+
* allowPublicAccess: true
|
|
191
|
+
* });
|
|
192
|
+
*
|
|
193
|
+
* const storageWorker = await Worker("storage", {
|
|
194
|
+
* name: "storage-worker",
|
|
195
|
+
* entrypoint: "./src/storage.ts",
|
|
196
|
+
* bindings: {
|
|
197
|
+
* UPLOADS: uploads,
|
|
198
|
+
* ASSETS: assets
|
|
199
|
+
* }
|
|
200
|
+
* });
|
|
201
|
+
*
|
|
202
|
+
* @see https://developers.cloudflare.com/workers/
|
|
203
|
+
*/
|
|
141
204
|
export const Worker = Resource(
|
|
142
205
|
"cloudflare::Worker",
|
|
143
206
|
{
|
package/src/cloudflare/zone.ts
CHANGED
|
@@ -245,6 +245,61 @@ export interface Zone extends Resource<"cloudflare::Zone"> {
|
|
|
245
245
|
};
|
|
246
246
|
}
|
|
247
247
|
|
|
248
|
+
/**
|
|
249
|
+
* A Cloudflare Zone represents a domain and its configuration settings on Cloudflare.
|
|
250
|
+
* Zones allow you to manage DNS, SSL/TLS, caching, security and other settings for a domain.
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* // Create a basic zone with default settings
|
|
254
|
+
* const basicZone = await Zone("example.com", {
|
|
255
|
+
* name: "example.com",
|
|
256
|
+
* type: "full",
|
|
257
|
+
* jumpStart: true
|
|
258
|
+
* });
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* // Create a zone with enhanced security settings
|
|
262
|
+
* const secureZone = await Zone("secure.example.com", {
|
|
263
|
+
* name: "secure.example.com",
|
|
264
|
+
* type: "full",
|
|
265
|
+
* settings: {
|
|
266
|
+
* ssl: "strict",
|
|
267
|
+
* alwaysUseHttps: "on",
|
|
268
|
+
* automaticHttpsRewrites: "on",
|
|
269
|
+
* minTlsVersion: "1.3",
|
|
270
|
+
* tls13: "zrt"
|
|
271
|
+
* }
|
|
272
|
+
* });
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* // Create a zone with optimized performance settings
|
|
276
|
+
* const fastZone = await Zone("fast.example.com", {
|
|
277
|
+
* name: "fast.example.com",
|
|
278
|
+
* settings: {
|
|
279
|
+
* browserCacheTtl: 7200,
|
|
280
|
+
* brotli: "on",
|
|
281
|
+
* zeroRtt: "on",
|
|
282
|
+
* http2: "on",
|
|
283
|
+
* http3: "on",
|
|
284
|
+
* earlyHints: "on"
|
|
285
|
+
* }
|
|
286
|
+
* });
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
* // Create a development zone with specific features
|
|
290
|
+
* const devZone = await Zone("dev.example.com", {
|
|
291
|
+
* name: "dev.example.com",
|
|
292
|
+
* settings: {
|
|
293
|
+
* developmentMode: "on",
|
|
294
|
+
* emailObfuscation: "on",
|
|
295
|
+
* hotlinkProtection: "on",
|
|
296
|
+
* ipv6: "on",
|
|
297
|
+
* websockets: "on"
|
|
298
|
+
* }
|
|
299
|
+
* });
|
|
300
|
+
*
|
|
301
|
+
* @see https://developers.cloudflare.com/dns/zone-setups/
|
|
302
|
+
*/
|
|
248
303
|
export const Zone = Resource(
|
|
249
304
|
"cloudflare::Zone",
|
|
250
305
|
async function (
|
package/src/context.ts
CHANGED
|
@@ -9,24 +9,33 @@ import type {
|
|
|
9
9
|
import type { Scope } from "./scope";
|
|
10
10
|
import type { State } from "./state";
|
|
11
11
|
|
|
12
|
-
export type Context<
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
export type Context<
|
|
13
|
+
Out extends Resource,
|
|
14
|
+
Props extends ResourceProps = ResourceProps,
|
|
15
|
+
> = CreateContext<Out> | UpdateContext<Out, Props> | DeleteContext<Out, Props>;
|
|
16
16
|
|
|
17
17
|
export interface CreateContext<Out extends Resource> extends BaseContext<Out> {
|
|
18
18
|
phase: "create";
|
|
19
19
|
output?: undefined;
|
|
20
|
+
props?: undefined;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
export interface UpdateContext<
|
|
23
|
+
export interface UpdateContext<
|
|
24
|
+
Out extends Resource,
|
|
25
|
+
Props extends ResourceProps = ResourceProps,
|
|
26
|
+
> extends BaseContext<Out> {
|
|
23
27
|
phase: "update";
|
|
24
28
|
output: Out;
|
|
29
|
+
props: Props;
|
|
25
30
|
}
|
|
26
31
|
|
|
27
|
-
export interface DeleteContext<
|
|
32
|
+
export interface DeleteContext<
|
|
33
|
+
Out extends Resource,
|
|
34
|
+
Props extends ResourceProps = ResourceProps,
|
|
35
|
+
> extends BaseContext<Out> {
|
|
28
36
|
phase: "delete";
|
|
29
37
|
output: Out;
|
|
38
|
+
props: Props;
|
|
30
39
|
}
|
|
31
40
|
|
|
32
41
|
export interface BaseContext<Out extends Resource> {
|
|
@@ -43,7 +52,6 @@ export interface BaseContext<Out extends Resource> {
|
|
|
43
52
|
* This will cause the resource to be deleted at the end of the stack's CREATE phase.
|
|
44
53
|
*/
|
|
45
54
|
replace(): void;
|
|
46
|
-
|
|
47
55
|
/**
|
|
48
56
|
* Terminate the resource lifecycle handler and destroy the resource.
|
|
49
57
|
*
|
|
@@ -60,12 +68,13 @@ export interface BaseContext<Out extends Resource> {
|
|
|
60
68
|
/**
|
|
61
69
|
* Create the Resource envelope (with Alchemy + User properties)
|
|
62
70
|
*/
|
|
71
|
+
(id: string, props: Omit<Out, keyof Resource>): Out;
|
|
63
72
|
(props: Omit<Out, keyof Resource>): Out;
|
|
64
73
|
}
|
|
65
74
|
|
|
66
75
|
export function context<
|
|
67
76
|
Kind extends string,
|
|
68
|
-
Props extends ResourceProps,
|
|
77
|
+
Props extends ResourceProps | undefined,
|
|
69
78
|
Out extends Resource,
|
|
70
79
|
>({
|
|
71
80
|
scope,
|
|
@@ -83,14 +92,24 @@ export function context<
|
|
|
83
92
|
id: ResourceID;
|
|
84
93
|
fqn: ResourceFQN;
|
|
85
94
|
seq: number;
|
|
95
|
+
props: Props;
|
|
86
96
|
state: State<Kind, Props, Out>;
|
|
87
97
|
replace: () => void;
|
|
88
98
|
}): Context<Out> {
|
|
89
|
-
function create(props: Omit<Out, "Kind" | "ID" | "Scope">): Out
|
|
99
|
+
function create(props: Omit<Out, "Kind" | "ID" | "Scope">): Out;
|
|
100
|
+
function create(id: string, props: Omit<Out, "Kind" | "ID" | "Scope">): Out;
|
|
101
|
+
function create(
|
|
102
|
+
...args:
|
|
103
|
+
| [props: Omit<Out, "Kind" | "ID" | "Scope">]
|
|
104
|
+
| [id: string, props: Omit<Out, "Kind" | "ID" | "Scope">]
|
|
105
|
+
): Out {
|
|
106
|
+
const [ID, props] =
|
|
107
|
+
typeof args[0] === "string" ? (args as [string, any]) : [id, args[0]];
|
|
108
|
+
|
|
90
109
|
return {
|
|
91
110
|
...props,
|
|
92
111
|
Kind: kind,
|
|
93
|
-
ID
|
|
112
|
+
ID,
|
|
94
113
|
FQN: fqn,
|
|
95
114
|
Scope: scope,
|
|
96
115
|
Seq: seq,
|
|
@@ -103,6 +122,7 @@ export function context<
|
|
|
103
122
|
fqn: fqn,
|
|
104
123
|
phase,
|
|
105
124
|
output: state.output,
|
|
125
|
+
props: state.props,
|
|
106
126
|
replace,
|
|
107
127
|
get: (key: string) => state.data[key],
|
|
108
128
|
set: async (key: string, value: any) => {
|
package/src/destroy.ts
CHANGED
|
@@ -23,12 +23,15 @@ export async function destroy<Type extends string>(
|
|
|
23
23
|
| [resource: Resource<Type> | undefined | null, options?: DestroyOptions]
|
|
24
24
|
): Promise<void> {
|
|
25
25
|
if (isScopeArgs(args)) {
|
|
26
|
-
const [scope
|
|
27
|
-
const
|
|
26
|
+
const [scope] = args;
|
|
27
|
+
const options = {
|
|
28
|
+
strategy: "sequential",
|
|
29
|
+
...(args[1] ?? {}),
|
|
30
|
+
} satisfies DestroyOptions;
|
|
31
|
+
|
|
28
32
|
// destroy all active resources
|
|
29
|
-
await destroy.all(Array.from(scope.resources.values()),
|
|
30
|
-
|
|
31
|
-
});
|
|
33
|
+
await destroy.all(Array.from(scope.resources.values()), options);
|
|
34
|
+
|
|
32
35
|
// then detect orphans and destroy them
|
|
33
36
|
const orphans = await scope.state.all();
|
|
34
37
|
await destroy.all(
|
|
@@ -52,7 +55,7 @@ export async function destroy<Type extends string>(
|
|
|
52
55
|
const Provider: Provider<Type> | undefined = PROVIDERS.get(instance.Kind);
|
|
53
56
|
if (!Provider) {
|
|
54
57
|
throw new Error(
|
|
55
|
-
`Cannot destroy resource type ${instance.Kind} - no provider found. You may need to import the provider in your alchemy.config.ts.`,
|
|
58
|
+
`Cannot destroy resource "${instance.FQN}" type ${instance.Kind} - no provider found. You may need to import the provider in your alchemy.config.ts.`,
|
|
56
59
|
);
|
|
57
60
|
}
|
|
58
61
|
|
|
@@ -67,10 +70,9 @@ export async function destroy<Type extends string>(
|
|
|
67
70
|
console.log(`Delete: "${instance.FQN}"`);
|
|
68
71
|
}
|
|
69
72
|
|
|
70
|
-
const state =
|
|
73
|
+
const state = await scope.state.get(instance.ID);
|
|
71
74
|
|
|
72
75
|
if (state === undefined) {
|
|
73
|
-
console.warn(`Resource "${instance.FQN}" not found`);
|
|
74
76
|
return;
|
|
75
77
|
}
|
|
76
78
|
|
|
@@ -81,6 +83,7 @@ export async function destroy<Type extends string>(
|
|
|
81
83
|
id: instance.ID,
|
|
82
84
|
fqn: instance.FQN,
|
|
83
85
|
seq: instance.Seq,
|
|
86
|
+
props: state.props,
|
|
84
87
|
state,
|
|
85
88
|
replace: () => {
|
|
86
89
|
throw new Error("Cannot replace a resource that is being deleted");
|