@develit-io/backend-sdk 5.29.1 → 5.30.1

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.
@@ -1,18 +1,12 @@
1
1
  'use strict';
2
2
 
3
- const worker = require('../shared/backend-sdk.n8SfX_xu.cjs');
3
+ const worker = require('../shared/backend-sdk.Vru_rcK6.cjs');
4
4
  const text = require('@std/text');
5
5
  const cloudflare = require('alchemy/cloudflare');
6
- const environment_consts = require('../shared/backend-sdk.ClVQ4AzB.cjs');
7
- const alchemy = require('alchemy');
8
- const state = require('alchemy/state');
6
+ require('../shared/backend-sdk.BdcrYpFD.cjs');
9
7
  require('@std/path');
10
8
  require('comment-json');
11
9
 
12
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
13
-
14
- const alchemy__default = /*#__PURE__*/_interopDefaultCompat(alchemy);
15
-
16
10
  const composeD1Arguments = ({
17
11
  resourceName
18
12
  }) => {
@@ -22,6 +16,20 @@ const composeD1Arguments = ({
22
16
  };
23
17
  };
24
18
 
19
+ const composeDlqArguments = ({
20
+ resourceName,
21
+ deliveryDelay = worker.QUEUE_DELIVERY_DELAY,
22
+ messageRetentionPeriod = worker.QUEUE_MESSAGE_RETENTION_PERIOD
23
+ }) => {
24
+ return {
25
+ name: resourceName,
26
+ settings: {
27
+ deliveryDelay,
28
+ messageRetentionPeriod
29
+ }
30
+ };
31
+ };
32
+
25
33
  const composeKvArguments = ({
26
34
  resourceName
27
35
  }) => {
@@ -32,17 +40,17 @@ const composeKvArguments = ({
32
40
 
33
41
  const composeQueueArguments = ({
34
42
  resourceName,
43
+ dlq,
35
44
  deliveryDelay = worker.QUEUE_DELIVERY_DELAY,
36
- messageRetentionPeriod = worker.QUEUE_MESSAGE_RETENTION_PERIOD,
37
- dlq
45
+ messageRetentionPeriod = worker.QUEUE_MESSAGE_RETENTION_PERIOD
38
46
  }) => {
39
47
  return {
40
48
  name: resourceName,
49
+ dlq,
41
50
  settings: {
42
51
  deliveryDelay,
43
52
  messageRetentionPeriod
44
- },
45
- dlq
53
+ }
46
54
  };
47
55
  };
48
56
 
@@ -52,9 +60,9 @@ const composeR2Arguments = ({
52
60
  }) => {
53
61
  return {
54
62
  name: resourceName,
63
+ storageClass,
55
64
  jurisdiction: worker.R2_JURISDICTION,
56
- locationHint: worker.R2_LOCATION_HINT,
57
- storageClass
65
+ locationHint: worker.R2_LOCATION_HINT
58
66
  };
59
67
  };
60
68
 
@@ -72,42 +80,23 @@ const composeResourceName = ({
72
80
  return `${project}-${text.toKebabCase(resourceName).toLowerCase()}-${environment}`;
73
81
  };
74
82
 
75
- const composeDlqArguments = ({
76
- resourceName,
77
- deliveryDelay = worker.QUEUE_DELIVERY_DELAY,
78
- messageRetentionPeriod = worker.QUEUE_MESSAGE_RETENTION_PERIOD
79
- }) => {
80
- return {
81
- name: resourceName,
82
- settings: {
83
- deliveryDelay,
84
- messageRetentionPeriod
85
- }
86
- };
87
- };
88
-
89
83
  class Deployment {
90
84
  project;
91
85
  environment;
92
- alchemy;
86
+ // TODO: Check if the type is most correct
87
+ // TODO: Keeping this in class creates issues with destroy
88
+ // public alchemy: Promise<Awaited<ReturnType<typeof alchemy>>>
93
89
  constructor({ project }) {
94
90
  this.project = project;
95
91
  this.environment = Bun.env.ENVIRONMENT || "unknown";
96
- this.alchemy = alchemy__default(project, {
97
- stateStore: (scope) => {
98
- return new state.CloudflareStateStore(scope, {
99
- scriptName: environment_consts.ALCHEMY_STATE_STORE
100
- });
101
- },
102
- stage: Bun.env.ENVIRONMENT || "unknown"
103
- });
104
92
  }
93
+ // TODO: Keeping this in class creates issues with destroy
105
94
  /**
106
95
  * Finalizes the deployment and correctly quits the Alchemy process.
107
96
  */
108
- async finalize() {
109
- return (await this.alchemy).finalize();
110
- }
97
+ // async finalize() {
98
+ // return (await this.alchemy).finalize()
99
+ // }
111
100
  /**
112
101
  * Creates an instance of Cloudflare KV.
113
102
  */
@@ -141,11 +130,11 @@ class Deployment {
141
130
  );
142
131
  }
143
132
  /**
144
- * Creates an instance of Cloudflare Queue.
133
+ * Creates an instance of Cloudflare Queue. A DLQ is created automatically.
145
134
  */
146
135
  async queue(options) {
147
136
  const { resourceName, deliveryDelay, messageRetentionPeriod } = options;
148
- const dlq = await this.dlq({
137
+ const deadLetterQueue = await this.dlq({
149
138
  resourceName
150
139
  });
151
140
  return await cloudflare.Queue(
@@ -156,9 +145,9 @@ class Deployment {
156
145
  environment: this.environment,
157
146
  resourceName
158
147
  }),
148
+ dlq: deadLetterQueue,
159
149
  deliveryDelay,
160
- messageRetentionPeriod,
161
- dlq
150
+ messageRetentionPeriod
162
151
  })
163
152
  );
164
153
  }
@@ -208,6 +197,7 @@ class Deployment {
208
197
  resourceName: className,
209
198
  resource: "durable-object"
210
199
  }),
200
+ // TODO: Create util
211
201
  {
212
202
  // TODO: Create util
213
203
  className: `${className}DurableObject`,
@@ -227,12 +217,11 @@ class Deployment {
227
217
  assets,
228
218
  crons,
229
219
  bindings,
230
- variables,
231
- secrets,
232
220
  eventSources
233
221
  } = options;
234
222
  const identifierName = composeIdentifierName({
235
223
  resourceName,
224
+ // TODO: Convert to a util
236
225
  resource: resource || "worker"
237
226
  });
238
227
  const workerConfig = await worker.loadWorkerConfig({ path });
@@ -243,10 +232,12 @@ class Deployment {
243
232
  deadLetterQueue: queue.dlq,
244
233
  batchSize: worker.QUEUE_MAX_BATCH_SIZE,
245
234
  maxWaitTimeMs: worker.QUEUE_MAX_BATCH_TIMEOUT
235
+ // TODO: Watch out for the type
246
236
  }
247
237
  };
248
238
  });
249
239
  return await cloudflare.Worker(
240
+ // TODO: Make it to use composeIdentifierName similary to other resources
250
241
  identifierName,
251
242
  worker.composeWorkerArguments({
252
243
  resourceName: composeResourceName({
@@ -258,14 +249,17 @@ class Deployment {
258
249
  entrypoint: `${path}/src/index.ts`,
259
250
  domains,
260
251
  assets,
252
+ // TODO: Convert to a util
261
253
  crons: crons || worker.extractWorkerCrons({
262
254
  workerConfig,
263
255
  environment: this.environment
264
256
  }),
265
257
  bindings: {
266
258
  ...bindings,
267
- ...variables,
268
- ...secrets
259
+ ...worker.extractWorkerVars({
260
+ workerConfig,
261
+ environment: this.environment
262
+ })
269
263
  },
270
264
  eventSources: consumers
271
265
  })
@@ -275,15 +269,13 @@ class Deployment {
275
269
  * Creates an instance of Cloudflare Worker as a service.
276
270
  */
277
271
  async service(options) {
278
- const { resourceName, bindings, variables, secrets, eventSources } = options;
272
+ const { resourceName, bindings, eventSources } = options;
279
273
  return await this.worker({
280
274
  resourceName,
281
275
  resource: "service",
282
276
  // TODO: Convert to util
283
277
  path: `./services/${resourceName}`,
284
278
  bindings,
285
- variables,
286
- secrets,
287
279
  eventSources
288
280
  });
289
281
  }
@@ -291,14 +283,7 @@ class Deployment {
291
283
  * Creates an instance of Cloudflare Worker as an orchestrator.
292
284
  */
293
285
  async orchestrator(options) {
294
- const {
295
- resourceName,
296
- domains,
297
- bindings,
298
- variables,
299
- secrets,
300
- eventSources
301
- } = options;
286
+ const { resourceName, domains, bindings, eventSources } = options;
302
287
  return await this.worker({
303
288
  resourceName,
304
289
  resource: "orchestrator",
@@ -306,8 +291,6 @@ class Deployment {
306
291
  path: `./apps/${resourceName}`,
307
292
  domains,
308
293
  bindings,
309
- variables,
310
- secrets,
311
294
  eventSources
312
295
  });
313
296
  }
@@ -315,7 +298,7 @@ class Deployment {
315
298
  * Creates an instance of Cloudflare Worker as a client.
316
299
  */
317
300
  async client(options) {
318
- const { resourceName, domains, bindings, variables, secrets } = options;
301
+ const { resourceName, domains, bindings, variables } = options;
319
302
  return await cloudflare.Nuxt(
320
303
  composeIdentifierName({
321
304
  resourceName,
@@ -336,8 +319,7 @@ class Deployment {
336
319
  domains,
337
320
  bindings: {
338
321
  ...bindings,
339
- ...variables,
340
- ...secrets
322
+ ...variables
341
323
  },
342
324
  // TODO: Convert to util
343
325
  cwd: `./apps/${resourceName}`
@@ -348,9 +330,11 @@ class Deployment {
348
330
 
349
331
  exports.composeWorkerArguments = worker.composeWorkerArguments;
350
332
  exports.extractWorkerCrons = worker.extractWorkerCrons;
333
+ exports.extractWorkerVars = worker.extractWorkerVars;
351
334
  exports.loadWorkerConfig = worker.loadWorkerConfig;
352
335
  exports.Deployment = Deployment;
353
336
  exports.composeD1Arguments = composeD1Arguments;
337
+ exports.composeDlqArguments = composeDlqArguments;
354
338
  exports.composeIdentifierName = composeIdentifierName;
355
339
  exports.composeKvArguments = composeKvArguments;
356
340
  exports.composeQueueArguments = composeQueueArguments;
@@ -2,27 +2,24 @@ import * as alchemy_cloudflare from 'alchemy/cloudflare';
2
2
  import { KVNamespace, D1Database, Queue, R2Bucket, DurableObjectNamespace, Bindings, Worker } from 'alchemy/cloudflare';
3
3
  import { P as Project } from '../shared/backend-sdk.CP78x0gl.cjs';
4
4
  import { E as Environment } from '../shared/backend-sdk.CYcpgphg.cjs';
5
- import { W as WorkerType$1, R as Resource } from '../shared/backend-sdk.D8N5si7y.cjs';
6
- export { c as composeWorkerArguments, e as extractWorkerCrons, l as loadWorkerConfig } from '../shared/backend-sdk.D8N5si7y.cjs';
7
- import alchemy from 'alchemy';
5
+ import { W as WorkerType$1, R as Resource } from '../shared/backend-sdk.CdngrAa0.cjs';
6
+ export { c as composeWorkerArguments, e as extractWorkerCrons, a as extractWorkerVars, l as loadWorkerConfig } from '../shared/backend-sdk.CdngrAa0.cjs';
8
7
 
9
8
  declare class Deployment {
10
9
  project: Project;
11
10
  environment: Environment;
12
- alchemy: Promise<Awaited<ReturnType<typeof alchemy>>>;
13
11
  constructor({ project }: {
14
12
  project: Project;
15
13
  });
16
14
  /**
17
15
  * Finalizes the deployment and correctly quits the Alchemy process.
18
16
  */
19
- finalize(): Promise<void>;
20
17
  /**
21
18
  * Creates an instance of Cloudflare KV.
22
19
  */
23
20
  kv(options: {
24
21
  /**
25
- * Name of the KV. Do not include the 'kv' prefix.
22
+ * Name of the instance. Do not include a 'kv' prefix.
26
23
  */
27
24
  resourceName: string;
28
25
  }): Promise<KVNamespace>;
@@ -31,24 +28,24 @@ declare class Deployment {
31
28
  */
32
29
  d1(options: {
33
30
  /**
34
- * Name of the D1. Do not include the 'd1' prefix.
31
+ * Name of the instance. Do not include a 'd1' prefix.
35
32
  */
36
33
  resourceName: string;
37
34
  }): Promise<D1Database>;
38
35
  /**
39
- * Creates an instance of Cloudflare Queue.
36
+ * Creates an instance of Cloudflare Queue. A DLQ is created automatically.
40
37
  */
41
38
  queue(options: {
42
39
  /**
43
- * Name of the Queue. Do not include the 'queue' prefix.
40
+ * Name of the instance. Do not include a 'queue' prefix.
44
41
  */
45
42
  resourceName: string;
46
43
  /**
47
- * The number of seconds to delay delivery of messages to the queue.
44
+ * The number of seconds to delay delivery of messages to the instance.
48
45
  */
49
46
  deliveryDelay?: number;
50
47
  /**
51
- * The number of seconds a message will remain in the queue before being deleted.
48
+ * The number of seconds a message will remain in the instance before being deleted.
52
49
  */
53
50
  messageRetentionPeriod?: number;
54
51
  }): Promise<Queue<unknown>>;
@@ -57,15 +54,15 @@ declare class Deployment {
57
54
  */
58
55
  dlq(options: {
59
56
  /**
60
- * Name of the DLQ. Do not include the 'dlq' or 'queue' prefix.
57
+ * Name of the instance. Do not include a 'dlq' or 'queue' prefix.
61
58
  */
62
59
  resourceName: string;
63
60
  /**
64
- * The number of seconds to delay delivery of messages to the queue.
61
+ * The number of seconds to delay delivery of messages to the instance.
65
62
  */
66
63
  deliveryDelay?: number;
67
64
  /**
68
- * The number of seconds a message will remain in the queue before being deleted.
65
+ * The number of seconds a message will remain in the instance before being deleted.
69
66
  */
70
67
  messageRetentionPeriod?: number;
71
68
  }): Promise<Queue<unknown>>;
@@ -74,11 +71,11 @@ declare class Deployment {
74
71
  */
75
72
  r2(options: {
76
73
  /**
77
- * Name of the R2. Do not include the 'r2' prefix.
74
+ * Name of the instance. Do not include an 'r2' prefix.
78
75
  */
79
76
  resourceName: string;
80
77
  /**
81
- * The storage class for the R2 bucket.
78
+ * The storage class that the instance should take on.
82
79
  */
83
80
  storageClass?: 'Standard' | 'InfrequentAccess';
84
81
  }): Promise<R2Bucket>;
@@ -87,7 +84,7 @@ declare class Deployment {
87
84
  */
88
85
  durableObject(options: {
89
86
  /**
90
- * Name of the Durable Object class. Do not include the 'durable-object' or 'do' prefix.
87
+ * Name of the instance class. Do not include a 'durable-object' or 'do' prefix.
91
88
  */
92
89
  className: string;
93
90
  }): Promise<DurableObjectNamespace<any>>;
@@ -96,43 +93,35 @@ declare class Deployment {
96
93
  */
97
94
  worker(options: {
98
95
  /**
99
- * Name of the Worker. Do not include the 'worker' prefix.
96
+ * Name of the instance. Do not include the 'worker' prefix.
100
97
  */
101
98
  resourceName: string;
102
99
  /**
103
- * Type of the Worker.
100
+ * Type of the instance.
104
101
  */
105
102
  resource?: WorkerType$1;
106
103
  /**
107
- * Path to the root of the Worker.
104
+ * Path to the root of the instance.
108
105
  */
109
106
  path: string;
110
107
  /**
111
- * Custom domains to bind to the Worker.
108
+ * Custom domains to bind to the instance.
112
109
  */
113
110
  domains?: string[];
114
111
  /**
115
- * Static assets of the Worker.
112
+ * Static assets for the instance.
116
113
  */
117
114
  assets?: Bindings;
118
115
  /**
119
- * Cron expressions for the trigger of the Worker.
116
+ * Cron expressions for the triggers of the instange.
120
117
  */
121
118
  crons?: string[];
122
119
  /**
123
- * Bindings of the Worker.
120
+ * Bindings of the instance.
124
121
  */
125
122
  bindings?: Bindings;
126
123
  /**
127
- * Environment variables of the Worker.
128
- */
129
- variables?: Bindings;
130
- /**
131
- * Secrets of the Worker.
132
- */
133
- secrets?: Bindings;
134
- /**
135
- * Event sources for the service to consume.
124
+ * Event sources for the instance to consume.
136
125
  */
137
126
  eventSources?: Queue[];
138
127
  }): Promise<Worker<Bindings, Rpc.WorkerEntrypointBranded>>;
@@ -141,23 +130,15 @@ declare class Deployment {
141
130
  */
142
131
  service(options: {
143
132
  /**
144
- * Name of the service. Do not include the 'service' prefix.
133
+ * Name of the instance. Do not include a 'service' prefix.
145
134
  */
146
135
  resourceName: string;
147
136
  /**
148
- * Bindings of the Worker.
137
+ * Bindings of the instance.
149
138
  */
150
139
  bindings?: Bindings;
151
140
  /**
152
- * Environment variables of the Worker.
153
- */
154
- variables?: Bindings;
155
- /**
156
- * Secrets of the Worker.
157
- */
158
- secrets?: Bindings;
159
- /**
160
- * Event sources for the service to consume.
141
+ * Event sources for the instance to consume.
161
142
  */
162
143
  eventSources?: Queue[];
163
144
  }): Promise<Worker<Bindings, Rpc.WorkerEntrypointBranded>>;
@@ -166,27 +147,19 @@ declare class Deployment {
166
147
  */
167
148
  orchestrator(options: {
168
149
  /**
169
- * Name of the orchestrator. Do not include the 'orchestrator' prefix.
150
+ * Name of the instance. Do not include an 'orchestrator' prefix.
170
151
  */
171
152
  resourceName: string;
172
153
  /**
173
- * Custom domains to bind to the Worker.
154
+ * Custom domains to bind to the instance.
174
155
  */
175
156
  domains?: string[];
176
157
  /**
177
- * Bindings of the Worker.
158
+ * Bindings of the instance.
178
159
  */
179
160
  bindings?: Bindings;
180
161
  /**
181
- * Environment variables of the Worker.
182
- */
183
- variables?: Bindings;
184
- /**
185
- * Secrets of the Worker.
186
- */
187
- secrets?: Bindings;
188
- /**
189
- * Event sources for the orchestrator to consume.
162
+ * Event sources for the instance to consume.
190
163
  */
191
164
  eventSources?: Queue[];
192
165
  }): Promise<Worker<Bindings, Rpc.WorkerEntrypointBranded>>;
@@ -195,25 +168,21 @@ declare class Deployment {
195
168
  */
196
169
  client(options: {
197
170
  /**
198
- * Name of the client. Do not include the 'client' prefix.
171
+ * Name of the instance. Do not include a 'client' prefix.
199
172
  */
200
173
  resourceName: string;
201
174
  /**
202
- * Custom domains to bind to the Worker.
175
+ * Custom domains to bind to the instance.
203
176
  */
204
177
  domains?: string[];
205
178
  /**
206
- * Bindings of the Worker.
179
+ * Bindings of the instance.
207
180
  */
208
181
  bindings?: Bindings;
209
182
  /**
210
- * Environment variables of the Worker.
183
+ * Environment variables of the instance.
211
184
  */
212
185
  variables?: Bindings;
213
- /**
214
- * Secrets of the Worker.
215
- */
216
- secrets?: Bindings;
217
186
  }): Promise<Worker<{
218
187
  [x: string]: alchemy_cloudflare.Binding;
219
188
  } & {
@@ -228,24 +197,36 @@ declare const composeD1Arguments: ({ resourceName, }: {
228
197
  primaryLocationHint: "weur";
229
198
  };
230
199
 
200
+ declare const composeDlqArguments: ({ resourceName, deliveryDelay, messageRetentionPeriod, }: {
201
+ resourceName: string;
202
+ deliveryDelay?: number;
203
+ messageRetentionPeriod?: number;
204
+ }) => {
205
+ name: string;
206
+ settings: {
207
+ deliveryDelay: number;
208
+ messageRetentionPeriod: number;
209
+ };
210
+ };
211
+
231
212
  declare const composeKvArguments: ({ resourceName, }: {
232
213
  resourceName: string;
233
214
  }) => {
234
215
  title: string;
235
216
  };
236
217
 
237
- declare const composeQueueArguments: ({ resourceName, deliveryDelay, messageRetentionPeriod, dlq, }: {
218
+ declare const composeQueueArguments: ({ resourceName, dlq, deliveryDelay, messageRetentionPeriod, }: {
238
219
  resourceName: string;
220
+ dlq: Queue;
239
221
  deliveryDelay?: number;
240
222
  messageRetentionPeriod?: number;
241
- dlq: Queue;
242
223
  }) => {
243
224
  name: string;
225
+ dlq: Queue;
244
226
  settings: {
245
227
  deliveryDelay: number;
246
228
  messageRetentionPeriod: number;
247
229
  };
248
- dlq: Queue;
249
230
  };
250
231
 
251
232
  declare const composeR2Arguments: ({ resourceName, storageClass, }: {
@@ -253,9 +234,9 @@ declare const composeR2Arguments: ({ resourceName, storageClass, }: {
253
234
  storageClass?: "Standard" | "InfrequentAccess";
254
235
  }) => {
255
236
  name: string;
237
+ storageClass: "Standard" | "InfrequentAccess";
256
238
  jurisdiction: "eu";
257
239
  locationHint: string;
258
- storageClass: "Standard" | "InfrequentAccess";
259
240
  };
260
241
 
261
242
  declare const composeIdentifierName: ({ resource, resourceName, }: {
@@ -268,4 +249,4 @@ declare const composeResourceName: ({ project, environment, resourceName, }: {
268
249
  resourceName: string;
269
250
  }) => string;
270
251
 
271
- export { Deployment, composeD1Arguments, composeIdentifierName, composeKvArguments, composeQueueArguments, composeR2Arguments, composeResourceName };
252
+ export { Deployment, composeD1Arguments, composeDlqArguments, composeIdentifierName, composeKvArguments, composeQueueArguments, composeR2Arguments, composeResourceName };