oblaka-iac 0.0.13 → 0.0.15

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oblaka-iac",
3
- "version": "0.0.13",
3
+ "version": "0.0.15",
4
4
  "main": "./src/index.ts",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -48,6 +48,19 @@ export class D1Database implements BindableResource<D1DatabaseState> {
48
48
  }
49
49
  }
50
50
 
51
+ // Adopt an existing database instead of creating a duplicate. D1 allows
52
+ // multiple databases with the same name, so on lost state a blind create
53
+ // would silently spawn a second, empty DB and the binding would point at
54
+ // it — data loss. Look it up by name first and adopt it.
55
+ const existingDatabases = await args.context.client.fetch<{ uuid: string; name: string }[]>({
56
+ url: `/d1/database?name=${encodeURIComponent(remoteName)}`,
57
+ method: 'GET',
58
+ })
59
+ const existingDatabase = existingDatabases.find(d => d.name === remoteName)
60
+ if (existingDatabase) {
61
+ return { name: remoteName, id: existingDatabase.uuid }
62
+ }
63
+
51
64
  const result = await args.context.client.fetch<{ uuid: string }>({
52
65
  url: `/d1/database`,
53
66
  method: 'POST',
@@ -53,6 +53,18 @@ export class Queue implements BindableResource<QueueState> {
53
53
  }
54
54
  }
55
55
 
56
+ // Adopt an existing queue instead of failing on create. On lost state a
57
+ // blind create conflicts with the already-existing queue; look it up by
58
+ // name and adopt it.
59
+ const existingQueues = await args.context.client.fetch<{ queue_id: string; queue_name: string }[]>({
60
+ url: `/queues?per_page=1000`,
61
+ method: 'GET',
62
+ })
63
+ const existingQueue = existingQueues.find(q => q.queue_name === remoteName)
64
+ if (existingQueue) {
65
+ return { id: existingQueue.queue_id, name: remoteName }
66
+ }
67
+
56
68
  const result = await args.context.client.fetch<{ queue_id: string }>({
57
69
  url: `/queues`,
58
70
  method: 'POST',
@@ -44,6 +44,19 @@ export class R2Bucket implements BindableResource<R2BucketState> {
44
44
  }
45
45
  }
46
46
 
47
+ // Adopt an existing bucket instead of failing on create. On lost state a
48
+ // blind create returns a conflict for the already-existing bucket; look
49
+ // it up by name and adopt it (bucket contents are untouched either way).
50
+ const existingBuckets = await args.context.client.fetch<{ buckets: { name: string }[] }>({
51
+ url: `/r2/buckets?per_page=1000`,
52
+ method: 'GET',
53
+ })
54
+ if (existingBuckets.buckets?.some(b => b.name === remoteName)) {
55
+ return {
56
+ name: remoteName,
57
+ }
58
+ }
59
+
47
60
  await args.context.client.fetch({
48
61
  url: `/r2/buckets`,
49
62
  method: 'POST',
@@ -15,32 +15,31 @@ export class Worker implements BindableResource<WorkerState> {
15
15
  deleteDurableObjectsOnRemoval?: boolean
16
16
  }
17
17
  & Partial<
18
- Pick<
18
+ Omit<
19
19
  Config,
20
- | 'main'
21
- | 'compatibility_date'
22
- | 'vars'
23
- | 'find_additional_modules'
24
- | 'base_dir'
25
- | 'preview_urls'
26
- | 'routes'
27
- | 'route'
28
- | 'observability'
29
- | 'logpush'
30
- | 'rules'
31
- | 'limits'
32
- | 'no_bundle'
33
- | 'keep_names'
34
- | 'first_party_worker'
35
- | 'minify'
36
- | 'assets'
37
- | 'compliance_region'
38
- | 'build'
39
- | 'define'
40
- | 'jsx_factory'
41
- | 'jsx_fragment'
42
- | 'triggers'
43
- | 'upload_source_maps'
20
+ | 'name'
21
+ | 'compatibility_flags'
22
+ | 'account_id'
23
+ | 'kv_namespaces'
24
+ | 'r2_buckets'
25
+ | 'd1_databases'
26
+ | 'queues'
27
+ | 'durable_objects'
28
+ | 'migrations'
29
+ | 'workflows'
30
+ | 'containers'
31
+ | 'send_email'
32
+ | 'services'
33
+ | 'vectorize'
34
+ | 'analytics_engine_datasets'
35
+ | 'browser'
36
+ | 'images'
37
+ | 'version_metadata'
38
+ | 'worker_loaders'
39
+ | 'vpc_networks'
40
+ | 'ai_search_namespaces'
41
+ | 'flagship'
42
+ | 'cache'
44
43
  >
45
44
  >,
46
45
  ) {}
@@ -85,6 +84,19 @@ export class Worker implements BindableResource<WorkerState> {
85
84
  }
86
85
  }
87
86
 
87
+ // Adopt an existing worker instead of failing on create. State can be
88
+ // lost (e.g. the shared cf-state KV namespace gets clobbered by another
89
+ // project deploying the same env), in which case a blind create returns
90
+ // 10040 "already exists". Look it up by name and adopt it.
91
+ const existingWorkers = await args.context.client.fetch<{ id: string; name: string }[]>({
92
+ method: 'GET',
93
+ url: `/workers/workers?per_page=1000`,
94
+ })
95
+ const existingWorker = existingWorkers.find(w => w.name === remoteName)
96
+ if (existingWorker) {
97
+ return { id: existingWorker.id, name: remoteName }
98
+ }
99
+
88
100
  const result = await args.context.client.fetch<{ id: string }>({
89
101
  method: 'POST',
90
102
  url: `/workers/workers`,