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