@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,4 +1,4 @@
1
- import { D as D1_LOCATION_HINT, Q as QUEUE_MESSAGE_RETENTION_PERIOD, a as QUEUE_DELIVERY_DELAY, R as R2_STORAGE_CLASS, b as R2_LOCATION_HINT, d as R2_JURISDICTION, l as loadWorkerConfig, f as QUEUE_MAX_BATCH_TIMEOUT, g as QUEUE_MAX_BATCH_SIZE, c as composeWorkerArguments, e as extractWorkerCrons, C as COMPATIBILITY_FLAGS, h as COMPATIBILITY_DATE } from '../shared/backend-sdk.Cyo7INro.mjs';
1
+ import { D as D1_LOCATION_HINT, Q as QUEUE_MESSAGE_RETENTION_PERIOD, b as QUEUE_DELIVERY_DELAY, R as R2_LOCATION_HINT, d as R2_JURISDICTION, f as R2_STORAGE_CLASS, l as loadWorkerConfig, g as QUEUE_MAX_BATCH_TIMEOUT, h as QUEUE_MAX_BATCH_SIZE, c as composeWorkerArguments, a as extractWorkerVars, e as extractWorkerCrons, C as COMPATIBILITY_FLAGS, i as COMPATIBILITY_DATE } from '../shared/backend-sdk.c1cEUEGX.mjs';
2
2
  import { toKebabCase } from '@std/text';
3
3
  import { KVNamespace, D1Database, Queue, R2Bucket, DurableObjectNamespace, Worker, Nuxt } from 'alchemy/cloudflare';
4
4
  import { A as ALCHEMY_STATE_STORE } from '../shared/backend-sdk.BIVnu5aA.mjs';
@@ -16,6 +16,20 @@ const composeD1Arguments = ({
16
16
  };
17
17
  };
18
18
 
19
+ const composeDlqArguments = ({
20
+ resourceName,
21
+ deliveryDelay = QUEUE_DELIVERY_DELAY,
22
+ messageRetentionPeriod = QUEUE_MESSAGE_RETENTION_PERIOD
23
+ }) => {
24
+ return {
25
+ name: resourceName,
26
+ settings: {
27
+ deliveryDelay,
28
+ messageRetentionPeriod
29
+ }
30
+ };
31
+ };
32
+
19
33
  const composeKvArguments = ({
20
34
  resourceName
21
35
  }) => {
@@ -26,17 +40,17 @@ const composeKvArguments = ({
26
40
 
27
41
  const composeQueueArguments = ({
28
42
  resourceName,
43
+ dlq,
29
44
  deliveryDelay = QUEUE_DELIVERY_DELAY,
30
- messageRetentionPeriod = QUEUE_MESSAGE_RETENTION_PERIOD,
31
- dlq
45
+ messageRetentionPeriod = QUEUE_MESSAGE_RETENTION_PERIOD
32
46
  }) => {
33
47
  return {
34
48
  name: resourceName,
49
+ dlq,
35
50
  settings: {
36
51
  deliveryDelay,
37
52
  messageRetentionPeriod
38
- },
39
- dlq
53
+ }
40
54
  };
41
55
  };
42
56
 
@@ -46,9 +60,9 @@ const composeR2Arguments = ({
46
60
  }) => {
47
61
  return {
48
62
  name: resourceName,
63
+ storageClass,
49
64
  jurisdiction: R2_JURISDICTION,
50
- locationHint: R2_LOCATION_HINT,
51
- storageClass
65
+ locationHint: R2_LOCATION_HINT
52
66
  };
53
67
  };
54
68
 
@@ -69,6 +83,7 @@ const composeResourceName = ({
69
83
  class Deployment {
70
84
  project;
71
85
  environment;
86
+ // TODO: Check if the type is most correct
72
87
  alchemy;
73
88
  constructor({ project }) {
74
89
  this.project = project;
@@ -79,6 +94,7 @@ class Deployment {
79
94
  scriptName: ALCHEMY_STATE_STORE
80
95
  });
81
96
  },
97
+ // TODO: Convert to a util
82
98
  stage: Bun.env.ENVIRONMENT || "unknown"
83
99
  });
84
100
  }
@@ -121,21 +137,13 @@ class Deployment {
121
137
  );
122
138
  }
123
139
  /**
124
- * Creates an instance of Cloudflare Queue.
140
+ * Creates an instance of Cloudflare Queue. A DLQ is created automatically.
125
141
  */
126
142
  async queue(options) {
127
143
  const { resourceName, deliveryDelay, messageRetentionPeriod } = options;
128
- const dlq = await Queue(
129
- composeIdentifierName({ resourceName, resource: "dlq" }),
130
- {
131
- name: composeResourceName({
132
- project: this.project,
133
- environment: this.environment,
134
- // TODO: Convert to a util
135
- resourceName: `${resourceName}-dlq`
136
- })
137
- }
138
- );
144
+ const deadLetterQueue = await this.dlq({
145
+ resourceName
146
+ });
139
147
  return await Queue(
140
148
  composeIdentifierName({ resourceName, resource: "queue" }),
141
149
  composeQueueArguments({
@@ -144,9 +152,28 @@ class Deployment {
144
152
  environment: this.environment,
145
153
  resourceName
146
154
  }),
155
+ dlq: deadLetterQueue,
147
156
  deliveryDelay,
148
- messageRetentionPeriod,
149
- dlq
157
+ messageRetentionPeriod
158
+ })
159
+ );
160
+ }
161
+ /**
162
+ * Creates an instance of Cloudflare Queue as a DLQ.
163
+ */
164
+ async dlq(options) {
165
+ const { resourceName, deliveryDelay, messageRetentionPeriod } = options;
166
+ return await Queue(
167
+ composeIdentifierName({ resourceName, resource: "dlq" }),
168
+ composeDlqArguments({
169
+ resourceName: composeResourceName({
170
+ project: this.project,
171
+ environment: this.environment,
172
+ // TODO: Convert to a util
173
+ resourceName: `${resourceName}-dlq`
174
+ }),
175
+ deliveryDelay,
176
+ messageRetentionPeriod
150
177
  })
151
178
  );
152
179
  }
@@ -177,6 +204,7 @@ class Deployment {
177
204
  resourceName: className,
178
205
  resource: "durable-object"
179
206
  }),
207
+ // TODO: Create util
180
208
  {
181
209
  // TODO: Create util
182
210
  className: `${className}DurableObject`,
@@ -196,12 +224,11 @@ class Deployment {
196
224
  assets,
197
225
  crons,
198
226
  bindings,
199
- variables,
200
- secrets,
201
227
  eventSources
202
228
  } = options;
203
229
  const identifierName = composeIdentifierName({
204
230
  resourceName,
231
+ // TODO: Convert to a util
205
232
  resource: resource || "worker"
206
233
  });
207
234
  const workerConfig = await loadWorkerConfig({ path });
@@ -212,10 +239,12 @@ class Deployment {
212
239
  deadLetterQueue: queue.dlq,
213
240
  batchSize: QUEUE_MAX_BATCH_SIZE,
214
241
  maxWaitTimeMs: QUEUE_MAX_BATCH_TIMEOUT
242
+ // TODO: Watch out for the type
215
243
  }
216
244
  };
217
245
  });
218
246
  return await Worker(
247
+ // TODO: Make it to use composeIdentifierName similary to other resources
219
248
  identifierName,
220
249
  composeWorkerArguments({
221
250
  resourceName: composeResourceName({
@@ -227,14 +256,17 @@ class Deployment {
227
256
  entrypoint: `${path}/src/index.ts`,
228
257
  domains,
229
258
  assets,
259
+ // TODO: Convert to a util
230
260
  crons: crons || extractWorkerCrons({
231
261
  workerConfig,
232
262
  environment: this.environment
233
263
  }),
234
264
  bindings: {
235
265
  ...bindings,
236
- ...variables,
237
- ...secrets
266
+ ...extractWorkerVars({
267
+ workerConfig,
268
+ environment: this.environment
269
+ })
238
270
  },
239
271
  eventSources: consumers
240
272
  })
@@ -244,15 +276,13 @@ class Deployment {
244
276
  * Creates an instance of Cloudflare Worker as a service.
245
277
  */
246
278
  async service(options) {
247
- const { resourceName, bindings, variables, secrets, eventSources } = options;
279
+ const { resourceName, bindings, eventSources } = options;
248
280
  return await this.worker({
249
281
  resourceName,
250
282
  resource: "service",
251
283
  // TODO: Convert to util
252
284
  path: `./services/${resourceName}`,
253
285
  bindings,
254
- variables,
255
- secrets,
256
286
  eventSources
257
287
  });
258
288
  }
@@ -260,14 +290,7 @@ class Deployment {
260
290
  * Creates an instance of Cloudflare Worker as an orchestrator.
261
291
  */
262
292
  async orchestrator(options) {
263
- const {
264
- resourceName,
265
- domains,
266
- bindings,
267
- variables,
268
- secrets,
269
- eventSources
270
- } = options;
293
+ const { resourceName, domains, bindings, eventSources } = options;
271
294
  return await this.worker({
272
295
  resourceName,
273
296
  resource: "orchestrator",
@@ -275,8 +298,6 @@ class Deployment {
275
298
  path: `./apps/${resourceName}`,
276
299
  domains,
277
300
  bindings,
278
- variables,
279
- secrets,
280
301
  eventSources
281
302
  });
282
303
  }
@@ -284,7 +305,7 @@ class Deployment {
284
305
  * Creates an instance of Cloudflare Worker as a client.
285
306
  */
286
307
  async client(options) {
287
- const { resourceName, domains, bindings, variables, secrets } = options;
308
+ const { resourceName, domains, bindings, variables } = options;
288
309
  return await Nuxt(
289
310
  composeIdentifierName({
290
311
  resourceName,
@@ -305,8 +326,7 @@ class Deployment {
305
326
  domains,
306
327
  bindings: {
307
328
  ...bindings,
308
- ...variables,
309
- ...secrets
329
+ ...variables
310
330
  },
311
331
  // TODO: Convert to util
312
332
  cwd: `./apps/${resourceName}`
@@ -315,4 +335,4 @@ class Deployment {
315
335
  }
316
336
  }
317
337
 
318
- export { Deployment, composeD1Arguments, composeIdentifierName, composeKvArguments, composeQueueArguments, composeR2Arguments, composeResourceName, composeWorkerArguments, extractWorkerCrons, loadWorkerConfig };
338
+ export { Deployment, composeD1Arguments, composeDlqArguments, composeIdentifierName, composeKvArguments, composeQueueArguments, composeR2Arguments, composeResourceName, composeWorkerArguments, extractWorkerCrons, extractWorkerVars, loadWorkerConfig };
@@ -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
  require('../shared/backend-sdk.ClVQ4AzB.cjs');
5
5
  require('@std/path');
6
6
  require('comment-json');
@@ -9,4 +9,5 @@ require('comment-json');
9
9
 
10
10
  exports.composeWorkerArguments = worker.composeWorkerArguments;
11
11
  exports.extractWorkerCrons = worker.extractWorkerCrons;
12
+ exports.extractWorkerVars = worker.extractWorkerVars;
12
13
  exports.loadWorkerConfig = worker.loadWorkerConfig;
@@ -1,3 +1,3 @@
1
- export { c as composeWorkerArguments, e as extractWorkerCrons, l as loadWorkerConfig } from '../shared/backend-sdk.D8N5si7y.cjs';
1
+ export { c as composeWorkerArguments, e as extractWorkerCrons, a as extractWorkerVars, l as loadWorkerConfig } from '../shared/backend-sdk.CdngrAa0.cjs';
2
2
  import 'alchemy/cloudflare';
3
3
  import '../shared/backend-sdk.CYcpgphg.cjs';
@@ -1,3 +1,3 @@
1
- export { c as composeWorkerArguments, e as extractWorkerCrons, l as loadWorkerConfig } from '../shared/backend-sdk.OvCBQJUw.mjs';
1
+ export { c as composeWorkerArguments, e as extractWorkerCrons, a as extractWorkerVars, l as loadWorkerConfig } from '../shared/backend-sdk.C-0xIdM4.mjs';
2
2
  import 'alchemy/cloudflare';
3
3
  import '../shared/backend-sdk.CYcpgphg.mjs';
@@ -1,3 +1,3 @@
1
- export { c as composeWorkerArguments, e as extractWorkerCrons, l as loadWorkerConfig } from '../shared/backend-sdk.DSK5flKM.js';
1
+ export { c as composeWorkerArguments, e as extractWorkerCrons, a as extractWorkerVars, l as loadWorkerConfig } from '../shared/backend-sdk.qPzlx18G.js';
2
2
  import 'alchemy/cloudflare';
3
3
  import '../shared/backend-sdk.CYcpgphg.js';
@@ -1,4 +1,4 @@
1
- export { c as composeWorkerArguments, e as extractWorkerCrons, l as loadWorkerConfig } from '../shared/backend-sdk.Cyo7INro.mjs';
1
+ export { c as composeWorkerArguments, e as extractWorkerCrons, a as extractWorkerVars, l as loadWorkerConfig } from '../shared/backend-sdk.c1cEUEGX.mjs';
2
2
  import '../shared/backend-sdk.BIVnu5aA.mjs';
3
3
  import '@std/path';
4
4
  import 'comment-json';
@@ -4,11 +4,17 @@ import { E as Environment } from './backend-sdk.CYcpgphg.mjs';
4
4
  type Resource = 'kv' | 'd1' | 'queue' | 'dlq' | 'r2' | 'durable-object' | 'worker' | 'service' | 'orchestrator' | 'client';
5
5
  type WorkerType = 'service' | 'orchestrator' | 'client';
6
6
  interface WorkerConfig {
7
+ vars: {
8
+ [key: string]: string;
9
+ };
7
10
  triggers: {
8
11
  crons: string[];
9
12
  };
10
13
  env: {
11
14
  [key: string]: {
15
+ vars: {
16
+ [key: string]: string;
17
+ };
12
18
  triggers: {
13
19
  crons: string[];
14
20
  };
@@ -23,6 +29,12 @@ declare const extractWorkerCrons: ({ workerConfig, environment, }: {
23
29
  workerConfig: WorkerConfig;
24
30
  environment: Environment;
25
31
  }) => string[];
32
+ declare const extractWorkerVars: ({ workerConfig, environment, }: {
33
+ workerConfig: WorkerConfig;
34
+ environment: Environment;
35
+ }) => {
36
+ [key: string]: string;
37
+ };
26
38
  declare const composeWorkerArguments: ({ resourceName, entrypoint, assets, domains, crons, bindings, eventSources, }: {
27
39
  resourceName: string;
28
40
  entrypoint: string;
@@ -53,5 +65,5 @@ declare const composeWorkerArguments: ({ resourceName, entrypoint, assets, domai
53
65
  bindings: Bindings | undefined;
54
66
  };
55
67
 
56
- export { composeWorkerArguments as c, extractWorkerCrons as e, loadWorkerConfig as l };
68
+ export { extractWorkerVars as a, composeWorkerArguments as c, extractWorkerCrons as e, loadWorkerConfig as l };
57
69
  export type { Resource as R, WorkerType as W };
@@ -4,11 +4,17 @@ import { E as Environment } from './backend-sdk.CYcpgphg.cjs';
4
4
  type Resource = 'kv' | 'd1' | 'queue' | 'dlq' | 'r2' | 'durable-object' | 'worker' | 'service' | 'orchestrator' | 'client';
5
5
  type WorkerType = 'service' | 'orchestrator' | 'client';
6
6
  interface WorkerConfig {
7
+ vars: {
8
+ [key: string]: string;
9
+ };
7
10
  triggers: {
8
11
  crons: string[];
9
12
  };
10
13
  env: {
11
14
  [key: string]: {
15
+ vars: {
16
+ [key: string]: string;
17
+ };
12
18
  triggers: {
13
19
  crons: string[];
14
20
  };
@@ -23,6 +29,12 @@ declare const extractWorkerCrons: ({ workerConfig, environment, }: {
23
29
  workerConfig: WorkerConfig;
24
30
  environment: Environment;
25
31
  }) => string[];
32
+ declare const extractWorkerVars: ({ workerConfig, environment, }: {
33
+ workerConfig: WorkerConfig;
34
+ environment: Environment;
35
+ }) => {
36
+ [key: string]: string;
37
+ };
26
38
  declare const composeWorkerArguments: ({ resourceName, entrypoint, assets, domains, crons, bindings, eventSources, }: {
27
39
  resourceName: string;
28
40
  entrypoint: string;
@@ -53,5 +65,5 @@ declare const composeWorkerArguments: ({ resourceName, entrypoint, assets, domai
53
65
  bindings: Bindings | undefined;
54
66
  };
55
67
 
56
- export { composeWorkerArguments as c, extractWorkerCrons as e, loadWorkerConfig as l };
68
+ export { extractWorkerVars as a, composeWorkerArguments as c, extractWorkerCrons as e, loadWorkerConfig as l };
57
69
  export type { Resource as R, WorkerType as W };
@@ -33,6 +33,15 @@ const extractWorkerCrons = ({
33
33
  }
34
34
  return workerConfig.env[environment]?.triggers?.crons || [];
35
35
  };
36
+ const extractWorkerVars = ({
37
+ workerConfig,
38
+ environment
39
+ }) => {
40
+ if (!environment_consts.ENVIRONMENT.includes(String(environment))) {
41
+ return workerConfig.vars || [];
42
+ }
43
+ return workerConfig.env[environment]?.vars || [];
44
+ };
36
45
  const composeWorkerArguments = ({
37
46
  resourceName,
38
47
  entrypoint,
@@ -71,4 +80,5 @@ exports.R2_LOCATION_HINT = R2_LOCATION_HINT;
71
80
  exports.R2_STORAGE_CLASS = R2_STORAGE_CLASS;
72
81
  exports.composeWorkerArguments = composeWorkerArguments;
73
82
  exports.extractWorkerCrons = extractWorkerCrons;
83
+ exports.extractWorkerVars = extractWorkerVars;
74
84
  exports.loadWorkerConfig = loadWorkerConfig;
@@ -31,6 +31,15 @@ const extractWorkerCrons = ({
31
31
  }
32
32
  return workerConfig.env[environment]?.triggers?.crons || [];
33
33
  };
34
+ const extractWorkerVars = ({
35
+ workerConfig,
36
+ environment
37
+ }) => {
38
+ if (!ENVIRONMENT.includes(String(environment))) {
39
+ return workerConfig.vars || [];
40
+ }
41
+ return workerConfig.env[environment]?.vars || [];
42
+ };
34
43
  const composeWorkerArguments = ({
35
44
  resourceName,
36
45
  entrypoint,
@@ -57,4 +66,4 @@ const composeWorkerArguments = ({
57
66
  };
58
67
  };
59
68
 
60
- export { COMPATIBILITY_FLAGS as C, D1_LOCATION_HINT as D, QUEUE_MESSAGE_RETENTION_PERIOD as Q, R2_STORAGE_CLASS as R, QUEUE_DELIVERY_DELAY as a, R2_LOCATION_HINT as b, composeWorkerArguments as c, R2_JURISDICTION as d, extractWorkerCrons as e, QUEUE_MAX_BATCH_TIMEOUT as f, QUEUE_MAX_BATCH_SIZE as g, COMPATIBILITY_DATE as h, loadWorkerConfig as l };
69
+ export { COMPATIBILITY_FLAGS as C, D1_LOCATION_HINT as D, QUEUE_MESSAGE_RETENTION_PERIOD as Q, R2_LOCATION_HINT as R, extractWorkerVars as a, QUEUE_DELIVERY_DELAY as b, composeWorkerArguments as c, R2_JURISDICTION as d, extractWorkerCrons as e, R2_STORAGE_CLASS as f, QUEUE_MAX_BATCH_TIMEOUT as g, QUEUE_MAX_BATCH_SIZE as h, COMPATIBILITY_DATE as i, loadWorkerConfig as l };
@@ -4,11 +4,17 @@ import { E as Environment } from './backend-sdk.CYcpgphg.js';
4
4
  type Resource = 'kv' | 'd1' | 'queue' | 'dlq' | 'r2' | 'durable-object' | 'worker' | 'service' | 'orchestrator' | 'client';
5
5
  type WorkerType = 'service' | 'orchestrator' | 'client';
6
6
  interface WorkerConfig {
7
+ vars: {
8
+ [key: string]: string;
9
+ };
7
10
  triggers: {
8
11
  crons: string[];
9
12
  };
10
13
  env: {
11
14
  [key: string]: {
15
+ vars: {
16
+ [key: string]: string;
17
+ };
12
18
  triggers: {
13
19
  crons: string[];
14
20
  };
@@ -23,6 +29,12 @@ declare const extractWorkerCrons: ({ workerConfig, environment, }: {
23
29
  workerConfig: WorkerConfig;
24
30
  environment: Environment;
25
31
  }) => string[];
32
+ declare const extractWorkerVars: ({ workerConfig, environment, }: {
33
+ workerConfig: WorkerConfig;
34
+ environment: Environment;
35
+ }) => {
36
+ [key: string]: string;
37
+ };
26
38
  declare const composeWorkerArguments: ({ resourceName, entrypoint, assets, domains, crons, bindings, eventSources, }: {
27
39
  resourceName: string;
28
40
  entrypoint: string;
@@ -53,5 +65,5 @@ declare const composeWorkerArguments: ({ resourceName, entrypoint, assets, domai
53
65
  bindings: Bindings | undefined;
54
66
  };
55
67
 
56
- export { composeWorkerArguments as c, extractWorkerCrons as e, loadWorkerConfig as l };
68
+ export { extractWorkerVars as a, composeWorkerArguments as c, extractWorkerCrons as e, loadWorkerConfig as l };
57
69
  export type { Resource as R, WorkerType as W };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@develit-io/backend-sdk",
3
- "version": "5.29.0",
3
+ "version": "5.30.0",
4
4
  "description": "Develit Backend SDK",
5
5
  "author": "Develit.io",
6
6
  "license": "ISC",
@@ -38,19 +38,19 @@
38
38
  "dist"
39
39
  ],
40
40
  "dependencies": {
41
- "@cloudflare/workers-types": "4.20250923.0",
41
+ "@cloudflare/workers-types": "4.20251001.0",
42
42
  "@std/path": "npm:@jsr/std__path",
43
43
  "@std/text": "npm:@jsr/std__text",
44
- "comment-json": "^4.2.5",
45
- "drizzle-kit": "^0.31.4",
44
+ "comment-json": "^4.3.0",
45
+ "drizzle-kit": "^0.31.5",
46
46
  "drizzle-orm": "^0.44.5",
47
47
  "h3": "^1.15.4",
48
48
  "http-status-codes": "2.3.0",
49
49
  "superjson": "^2.2.2"
50
50
  },
51
51
  "peerDependencies": {
52
- "@develit-io/general-codes": "^1.12.1",
53
- "alchemy": "^0.69.0",
52
+ "@develit-io/general-codes": "^1.14.0",
53
+ "alchemy": "^0.69.1",
54
54
  "zod": "^4.1.8"
55
55
  }
56
56
  }