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