@develit-io/backend-sdk 5.14.0 → 5.14.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.
- package/dist/index.cjs +14 -68
- package/dist/index.d.cts +46 -54
- package/dist/index.d.mts +46 -54
- package/dist/index.d.ts +46 -54
- package/dist/index.mjs +14 -68
- package/package.json +5 -6
package/dist/index.cjs
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
const drizzleOrm = require('drizzle-orm');
|
|
4
4
|
const pgCore = require('drizzle-orm/pg-core');
|
|
5
5
|
const sqliteCore = require('drizzle-orm/sqlite-core');
|
|
6
|
+
const text = require('@std/text');
|
|
6
7
|
require('http-status-codes');
|
|
7
8
|
const z = require('zod/v4/core');
|
|
8
9
|
const h3 = require('h3');
|
|
@@ -51,37 +52,6 @@ const basePostgres = {
|
|
|
51
52
|
}).default(drizzleOrm.sql`null`)
|
|
52
53
|
};
|
|
53
54
|
|
|
54
|
-
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
55
|
-
const CAPITALIZED_WORD_REGEXP = /\p{Lu}\p{Ll}+/u; // e.g. Apple
|
|
56
|
-
const ACRONYM_REGEXP = /\p{Lu}+(?=(\p{Lu}\p{Ll})|\P{L}|\b)/u; // e.g. ID, URL, handles an acronym followed by a capitalized word e.g. HTMLElement
|
|
57
|
-
const LOWERCASED_WORD_REGEXP = /(\p{Ll}+)/u; // e.g. apple
|
|
58
|
-
const ANY_LETTERS = /\p{L}+/u; // will match any sequence of letters, including in languages without a concept of upper/lower case
|
|
59
|
-
const DIGITS_REGEXP = /\p{N}+/u; // e.g. 123
|
|
60
|
-
const WORD_OR_NUMBER_REGEXP = new RegExp(`${CAPITALIZED_WORD_REGEXP.source}|${ACRONYM_REGEXP.source}|${LOWERCASED_WORD_REGEXP.source}|${ANY_LETTERS.source}|${DIGITS_REGEXP.source}`, "gu");
|
|
61
|
-
function splitToWords(input) {
|
|
62
|
-
return input.match(WORD_OR_NUMBER_REGEXP) ?? [];
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
66
|
-
// This module is browser compatible.
|
|
67
|
-
/**
|
|
68
|
-
* Converts a string into snake_case.
|
|
69
|
-
*
|
|
70
|
-
* @example Usage
|
|
71
|
-
* ```ts
|
|
72
|
-
* import { toSnakeCase } from "@std/text/to-snake-case";
|
|
73
|
-
* import { assertEquals } from "@std/assert";
|
|
74
|
-
*
|
|
75
|
-
* assertEquals(toSnakeCase("deno is awesome"), "deno_is_awesome");
|
|
76
|
-
* ```
|
|
77
|
-
*
|
|
78
|
-
* @param input The string that is going to be converted into snake_case
|
|
79
|
-
* @returns The string as snake_case
|
|
80
|
-
*/ function toSnakeCase(input) {
|
|
81
|
-
input = input.trim();
|
|
82
|
-
return splitToWords(input).join("_").toLowerCase();
|
|
83
|
-
}
|
|
84
|
-
|
|
85
55
|
class Infrastructure {
|
|
86
56
|
project;
|
|
87
57
|
environment;
|
|
@@ -101,7 +71,8 @@ class Infrastructure {
|
|
|
101
71
|
resourceName,
|
|
102
72
|
bindingName
|
|
103
73
|
}) {
|
|
104
|
-
|
|
74
|
+
const convertedBindingName = bindingName ? text.toSnakeCase(bindingName) : `${text.toSnakeCase(resourceName)}_${resource}`;
|
|
75
|
+
return convertedBindingName.toUpperCase();
|
|
105
76
|
}
|
|
106
77
|
// TODO(Pookensivee): Make tests for this util
|
|
107
78
|
composeResourceName({ resourceName }) {
|
|
@@ -162,7 +133,7 @@ class Infrastructure {
|
|
|
162
133
|
}
|
|
163
134
|
};
|
|
164
135
|
}
|
|
165
|
-
// TODO: Solve the circular dependency on post
|
|
136
|
+
// TODO: Solve the circular dependency on post infrastructure deploy script
|
|
166
137
|
// TODO: Cannot assign a queue as a producer, work around: https://developers.cloudflare.com/workers/wrangler/commands/#queues-consumer-add-script-name
|
|
167
138
|
// async composeWorkerArguments({
|
|
168
139
|
// resourceName,
|
|
@@ -221,6 +192,7 @@ class Infrastructure {
|
|
|
221
192
|
// join(path, './wrangler.jsonc'),
|
|
222
193
|
// 'utf-8',
|
|
223
194
|
// )
|
|
195
|
+
// TODO: Use parse from comment-json
|
|
224
196
|
// const jsonString = workerConfigFile
|
|
225
197
|
// .replace(/\/\*[\s\S]*?\*\//g, '')
|
|
226
198
|
// .replace(/\/\/.*$/gm, '')
|
|
@@ -238,15 +210,9 @@ class Infrastructure {
|
|
|
238
210
|
// }
|
|
239
211
|
/**
|
|
240
212
|
* Creates an instance of Cloudflare KV.
|
|
241
|
-
* @param {Object} options - Configuration options for the KV instance.
|
|
242
|
-
* @param {string} options.name - Name of the KV. Do not include 'kv' prefix.
|
|
243
|
-
* @param {string?} options.bindingName - Name of the KV's binding. If not set then it's generated automatically based on the provided name.
|
|
244
|
-
* @returns {sst.cloudflare.Kv} An instance of Cloudflare KV.
|
|
245
213
|
*/
|
|
246
|
-
kv({
|
|
247
|
-
resourceName,
|
|
248
|
-
bindingName
|
|
249
|
-
}) {
|
|
214
|
+
kv(options) {
|
|
215
|
+
const { resourceName, bindingName } = options;
|
|
250
216
|
return new this.sst.cloudflare.Kv(
|
|
251
217
|
`${this.composeBindingName({ resource: "kv", resourceName, bindingName })}`,
|
|
252
218
|
this.composeKvArguments({
|
|
@@ -256,15 +222,9 @@ class Infrastructure {
|
|
|
256
222
|
}
|
|
257
223
|
/**
|
|
258
224
|
* Creates an instance of Cloudflare D1.
|
|
259
|
-
* @param {Object} options - Configuration options for the D1 instance.
|
|
260
|
-
* @param {string} options.name - Name of the D1. Do not include 'd1' prefix.
|
|
261
|
-
* @param {string?} options.bindingName - Name of the D1's binding. If not set then it's generated automatically based on the provided name.
|
|
262
|
-
* @returns {sst.cloudflare.D1} An instance of Cloudflare D1.
|
|
263
225
|
*/
|
|
264
|
-
d1({
|
|
265
|
-
resourceName,
|
|
266
|
-
bindingName
|
|
267
|
-
}) {
|
|
226
|
+
d1(options) {
|
|
227
|
+
const { resourceName, bindingName } = options;
|
|
268
228
|
return new this.sst.cloudflare.D1(
|
|
269
229
|
`${this.composeBindingName({ resource: "d1", resourceName, bindingName })}`,
|
|
270
230
|
this.composeD1Arguments({
|
|
@@ -274,17 +234,9 @@ class Infrastructure {
|
|
|
274
234
|
}
|
|
275
235
|
/**
|
|
276
236
|
* Creates an instance of Cloudflare Queue.
|
|
277
|
-
* @param {Object} options - Configuration options for the Queue instance.
|
|
278
|
-
* @param {string} options.name - Name of the Queue. Do not include 'queue' prefix.
|
|
279
|
-
* @param {string?} options.bindingName - Name of the Queue's binding. If not set then it's generated automatically based on the provided name.
|
|
280
|
-
* @returns {sst.cloudflare.Queue} An instance of Cloudflare Queue.
|
|
281
237
|
*/
|
|
282
|
-
queue({
|
|
283
|
-
resourceName,
|
|
284
|
-
bindingName,
|
|
285
|
-
deliveryDelay,
|
|
286
|
-
messageRetentionPeriod
|
|
287
|
-
}) {
|
|
238
|
+
queue(options) {
|
|
239
|
+
const { resourceName, bindingName, deliveryDelay, messageRetentionPeriod } = options;
|
|
288
240
|
return new this.sst.cloudflare.Queue(
|
|
289
241
|
`${this.composeBindingName({ resource: "queue", resourceName, bindingName })}`,
|
|
290
242
|
this.composeQueueArguments({
|
|
@@ -296,16 +248,9 @@ class Infrastructure {
|
|
|
296
248
|
}
|
|
297
249
|
/**
|
|
298
250
|
* Creates an instance of Cloudflare R2.
|
|
299
|
-
* @param {Object} options - Configuration options for the R2 instance.
|
|
300
|
-
* @param {string} options.name - Name of the R2. Do not include 'r2' prefix.
|
|
301
|
-
* @param {string?} options.bindingName - Name of the R2's binding. If not set then it's generated automatically based on the provided name.
|
|
302
|
-
* @returns {sst.cloudflare.Bucket} An instance of Cloudflare R2.
|
|
303
251
|
*/
|
|
304
|
-
r2({
|
|
305
|
-
resourceName,
|
|
306
|
-
bindingName,
|
|
307
|
-
storageClass
|
|
308
|
-
}) {
|
|
252
|
+
r2(options) {
|
|
253
|
+
const { resourceName, bindingName, storageClass } = options;
|
|
309
254
|
return new this.sst.cloudflare.Bucket(
|
|
310
255
|
`${this.composeBindingName({ resource: "r2", resourceName, bindingName })}`,
|
|
311
256
|
this.composeR2Arguments({
|
|
@@ -314,6 +259,7 @@ class Infrastructure {
|
|
|
314
259
|
})
|
|
315
260
|
);
|
|
316
261
|
}
|
|
262
|
+
// TODO: Solve the circular dependency on post infrastructure deploy script
|
|
317
263
|
// async worker({
|
|
318
264
|
// resourceName,
|
|
319
265
|
// bindingName,
|
package/dist/index.d.cts
CHANGED
|
@@ -30,35 +30,10 @@ type Resource = 'kv' | 'd1' | 'queue' | 'r2' | 'worker' | 'service' | 'orchestra
|
|
|
30
30
|
|
|
31
31
|
type Environment = number | 'dev' | 'test' | 'staging' | 'production';
|
|
32
32
|
|
|
33
|
-
interface
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
interface KvComponent {
|
|
38
|
-
name?: string;
|
|
39
|
-
[key: string]: unknown;
|
|
40
|
-
}
|
|
41
|
-
interface QueueComponent {
|
|
42
|
-
url?: string;
|
|
43
|
-
[key: string]: unknown;
|
|
44
|
-
}
|
|
45
|
-
interface WorkerComponent {
|
|
46
|
-
url?: string;
|
|
47
|
-
[key: string]: unknown;
|
|
48
|
-
}
|
|
49
|
-
interface BucketComponent {
|
|
50
|
-
name?: string;
|
|
51
|
-
[key: string]: unknown;
|
|
52
|
-
}
|
|
53
|
-
interface SSTCloudflare {
|
|
54
|
-
Kv: new (name: string, args?: unknown) => KvComponent;
|
|
55
|
-
Worker: new (name: string, args: unknown) => WorkerComponent;
|
|
56
|
-
Bucket: new (name: string, args?: unknown) => BucketComponent;
|
|
57
|
-
D1: new (name: string, args?: unknown) => D1Component;
|
|
58
|
-
Queue: new (name: string, args?: unknown) => QueueComponent;
|
|
59
|
-
}
|
|
60
|
-
interface SSTContext {
|
|
61
|
-
cloudflare: SSTCloudflare;
|
|
33
|
+
interface SstInstance {
|
|
34
|
+
cloudflare: {
|
|
35
|
+
[key: string]: any;
|
|
36
|
+
};
|
|
62
37
|
}
|
|
63
38
|
declare class Infrastructure {
|
|
64
39
|
private project;
|
|
@@ -67,7 +42,7 @@ declare class Infrastructure {
|
|
|
67
42
|
constructor({ project, environment, sst, }: {
|
|
68
43
|
project: Project;
|
|
69
44
|
environment: Environment;
|
|
70
|
-
sst:
|
|
45
|
+
sst: SstInstance;
|
|
71
46
|
});
|
|
72
47
|
composeBindingName({ resource, resourceName, bindingName, }: {
|
|
73
48
|
resource: Resource;
|
|
@@ -126,51 +101,68 @@ declare class Infrastructure {
|
|
|
126
101
|
};
|
|
127
102
|
/**
|
|
128
103
|
* Creates an instance of Cloudflare KV.
|
|
129
|
-
* @param {Object} options - Configuration options for the KV instance.
|
|
130
|
-
* @param {string} options.name - Name of the KV. Do not include 'kv' prefix.
|
|
131
|
-
* @param {string?} options.bindingName - Name of the KV's binding. If not set then it's generated automatically based on the provided name.
|
|
132
|
-
* @returns {sst.cloudflare.Kv} An instance of Cloudflare KV.
|
|
133
104
|
*/
|
|
134
|
-
kv(
|
|
105
|
+
kv(options: {
|
|
106
|
+
/**
|
|
107
|
+
* Name of the KV. Do not include the 'kv' prefix.
|
|
108
|
+
*/
|
|
135
109
|
resourceName: string;
|
|
110
|
+
/**
|
|
111
|
+
* Name of the KV's binding. If not set, it is generated automatically based on the provided name.
|
|
112
|
+
*/
|
|
136
113
|
bindingName?: string;
|
|
137
|
-
}):
|
|
114
|
+
}): any;
|
|
138
115
|
/**
|
|
139
116
|
* Creates an instance of Cloudflare D1.
|
|
140
|
-
* @param {Object} options - Configuration options for the D1 instance.
|
|
141
|
-
* @param {string} options.name - Name of the D1. Do not include 'd1' prefix.
|
|
142
|
-
* @param {string?} options.bindingName - Name of the D1's binding. If not set then it's generated automatically based on the provided name.
|
|
143
|
-
* @returns {sst.cloudflare.D1} An instance of Cloudflare D1.
|
|
144
117
|
*/
|
|
145
|
-
d1(
|
|
118
|
+
d1(options: {
|
|
119
|
+
/**
|
|
120
|
+
* Name of the D1. Do not include the 'd1' prefix.
|
|
121
|
+
*/
|
|
146
122
|
resourceName: string;
|
|
123
|
+
/**
|
|
124
|
+
* Name of the D1's binding. If not set, it is generated automatically based on the provided name.
|
|
125
|
+
*/
|
|
147
126
|
bindingName?: string;
|
|
148
|
-
}):
|
|
127
|
+
}): any;
|
|
149
128
|
/**
|
|
150
129
|
* Creates an instance of Cloudflare Queue.
|
|
151
|
-
* @param {Object} options - Configuration options for the Queue instance.
|
|
152
|
-
* @param {string} options.name - Name of the Queue. Do not include 'queue' prefix.
|
|
153
|
-
* @param {string?} options.bindingName - Name of the Queue's binding. If not set then it's generated automatically based on the provided name.
|
|
154
|
-
* @returns {sst.cloudflare.Queue} An instance of Cloudflare Queue.
|
|
155
130
|
*/
|
|
156
|
-
queue(
|
|
131
|
+
queue(options: {
|
|
132
|
+
/**
|
|
133
|
+
* Name of the Queue. Do not include the 'queue' prefix.
|
|
134
|
+
*/
|
|
157
135
|
resourceName: string;
|
|
136
|
+
/**
|
|
137
|
+
* Name of the Queue's binding. If not set, it is generated automatically based on the provided name.
|
|
138
|
+
*/
|
|
158
139
|
bindingName?: string;
|
|
140
|
+
/**
|
|
141
|
+
* The number of seconds to delay delivery of messages to the queue.
|
|
142
|
+
*/
|
|
159
143
|
deliveryDelay?: number;
|
|
144
|
+
/**
|
|
145
|
+
* The number of seconds a message will remain in the queue before being deleted.
|
|
146
|
+
*/
|
|
160
147
|
messageRetentionPeriod?: number;
|
|
161
|
-
}):
|
|
148
|
+
}): any;
|
|
162
149
|
/**
|
|
163
150
|
* Creates an instance of Cloudflare R2.
|
|
164
|
-
* @param {Object} options - Configuration options for the R2 instance.
|
|
165
|
-
* @param {string} options.name - Name of the R2. Do not include 'r2' prefix.
|
|
166
|
-
* @param {string?} options.bindingName - Name of the R2's binding. If not set then it's generated automatically based on the provided name.
|
|
167
|
-
* @returns {sst.cloudflare.Bucket} An instance of Cloudflare R2.
|
|
168
151
|
*/
|
|
169
|
-
r2(
|
|
152
|
+
r2(options: {
|
|
153
|
+
/**
|
|
154
|
+
* Name of the R2. Do not include the 'r2' prefix.
|
|
155
|
+
*/
|
|
170
156
|
resourceName: string;
|
|
157
|
+
/**
|
|
158
|
+
* Name of the R2's binding. If not set, it is generated automatically based on the provided name.
|
|
159
|
+
*/
|
|
171
160
|
bindingName?: string;
|
|
161
|
+
/**
|
|
162
|
+
* The storage class for the R2 bucket.
|
|
163
|
+
*/
|
|
172
164
|
storageClass?: 'Standard' | 'InfrequentAccess';
|
|
173
|
-
}):
|
|
165
|
+
}): any;
|
|
174
166
|
}
|
|
175
167
|
|
|
176
168
|
type InternalErrorResponseStatus = Exclude<StatusCodes, 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207>;
|
package/dist/index.d.mts
CHANGED
|
@@ -30,35 +30,10 @@ type Resource = 'kv' | 'd1' | 'queue' | 'r2' | 'worker' | 'service' | 'orchestra
|
|
|
30
30
|
|
|
31
31
|
type Environment = number | 'dev' | 'test' | 'staging' | 'production';
|
|
32
32
|
|
|
33
|
-
interface
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
interface KvComponent {
|
|
38
|
-
name?: string;
|
|
39
|
-
[key: string]: unknown;
|
|
40
|
-
}
|
|
41
|
-
interface QueueComponent {
|
|
42
|
-
url?: string;
|
|
43
|
-
[key: string]: unknown;
|
|
44
|
-
}
|
|
45
|
-
interface WorkerComponent {
|
|
46
|
-
url?: string;
|
|
47
|
-
[key: string]: unknown;
|
|
48
|
-
}
|
|
49
|
-
interface BucketComponent {
|
|
50
|
-
name?: string;
|
|
51
|
-
[key: string]: unknown;
|
|
52
|
-
}
|
|
53
|
-
interface SSTCloudflare {
|
|
54
|
-
Kv: new (name: string, args?: unknown) => KvComponent;
|
|
55
|
-
Worker: new (name: string, args: unknown) => WorkerComponent;
|
|
56
|
-
Bucket: new (name: string, args?: unknown) => BucketComponent;
|
|
57
|
-
D1: new (name: string, args?: unknown) => D1Component;
|
|
58
|
-
Queue: new (name: string, args?: unknown) => QueueComponent;
|
|
59
|
-
}
|
|
60
|
-
interface SSTContext {
|
|
61
|
-
cloudflare: SSTCloudflare;
|
|
33
|
+
interface SstInstance {
|
|
34
|
+
cloudflare: {
|
|
35
|
+
[key: string]: any;
|
|
36
|
+
};
|
|
62
37
|
}
|
|
63
38
|
declare class Infrastructure {
|
|
64
39
|
private project;
|
|
@@ -67,7 +42,7 @@ declare class Infrastructure {
|
|
|
67
42
|
constructor({ project, environment, sst, }: {
|
|
68
43
|
project: Project;
|
|
69
44
|
environment: Environment;
|
|
70
|
-
sst:
|
|
45
|
+
sst: SstInstance;
|
|
71
46
|
});
|
|
72
47
|
composeBindingName({ resource, resourceName, bindingName, }: {
|
|
73
48
|
resource: Resource;
|
|
@@ -126,51 +101,68 @@ declare class Infrastructure {
|
|
|
126
101
|
};
|
|
127
102
|
/**
|
|
128
103
|
* Creates an instance of Cloudflare KV.
|
|
129
|
-
* @param {Object} options - Configuration options for the KV instance.
|
|
130
|
-
* @param {string} options.name - Name of the KV. Do not include 'kv' prefix.
|
|
131
|
-
* @param {string?} options.bindingName - Name of the KV's binding. If not set then it's generated automatically based on the provided name.
|
|
132
|
-
* @returns {sst.cloudflare.Kv} An instance of Cloudflare KV.
|
|
133
104
|
*/
|
|
134
|
-
kv(
|
|
105
|
+
kv(options: {
|
|
106
|
+
/**
|
|
107
|
+
* Name of the KV. Do not include the 'kv' prefix.
|
|
108
|
+
*/
|
|
135
109
|
resourceName: string;
|
|
110
|
+
/**
|
|
111
|
+
* Name of the KV's binding. If not set, it is generated automatically based on the provided name.
|
|
112
|
+
*/
|
|
136
113
|
bindingName?: string;
|
|
137
|
-
}):
|
|
114
|
+
}): any;
|
|
138
115
|
/**
|
|
139
116
|
* Creates an instance of Cloudflare D1.
|
|
140
|
-
* @param {Object} options - Configuration options for the D1 instance.
|
|
141
|
-
* @param {string} options.name - Name of the D1. Do not include 'd1' prefix.
|
|
142
|
-
* @param {string?} options.bindingName - Name of the D1's binding. If not set then it's generated automatically based on the provided name.
|
|
143
|
-
* @returns {sst.cloudflare.D1} An instance of Cloudflare D1.
|
|
144
117
|
*/
|
|
145
|
-
d1(
|
|
118
|
+
d1(options: {
|
|
119
|
+
/**
|
|
120
|
+
* Name of the D1. Do not include the 'd1' prefix.
|
|
121
|
+
*/
|
|
146
122
|
resourceName: string;
|
|
123
|
+
/**
|
|
124
|
+
* Name of the D1's binding. If not set, it is generated automatically based on the provided name.
|
|
125
|
+
*/
|
|
147
126
|
bindingName?: string;
|
|
148
|
-
}):
|
|
127
|
+
}): any;
|
|
149
128
|
/**
|
|
150
129
|
* Creates an instance of Cloudflare Queue.
|
|
151
|
-
* @param {Object} options - Configuration options for the Queue instance.
|
|
152
|
-
* @param {string} options.name - Name of the Queue. Do not include 'queue' prefix.
|
|
153
|
-
* @param {string?} options.bindingName - Name of the Queue's binding. If not set then it's generated automatically based on the provided name.
|
|
154
|
-
* @returns {sst.cloudflare.Queue} An instance of Cloudflare Queue.
|
|
155
130
|
*/
|
|
156
|
-
queue(
|
|
131
|
+
queue(options: {
|
|
132
|
+
/**
|
|
133
|
+
* Name of the Queue. Do not include the 'queue' prefix.
|
|
134
|
+
*/
|
|
157
135
|
resourceName: string;
|
|
136
|
+
/**
|
|
137
|
+
* Name of the Queue's binding. If not set, it is generated automatically based on the provided name.
|
|
138
|
+
*/
|
|
158
139
|
bindingName?: string;
|
|
140
|
+
/**
|
|
141
|
+
* The number of seconds to delay delivery of messages to the queue.
|
|
142
|
+
*/
|
|
159
143
|
deliveryDelay?: number;
|
|
144
|
+
/**
|
|
145
|
+
* The number of seconds a message will remain in the queue before being deleted.
|
|
146
|
+
*/
|
|
160
147
|
messageRetentionPeriod?: number;
|
|
161
|
-
}):
|
|
148
|
+
}): any;
|
|
162
149
|
/**
|
|
163
150
|
* Creates an instance of Cloudflare R2.
|
|
164
|
-
* @param {Object} options - Configuration options for the R2 instance.
|
|
165
|
-
* @param {string} options.name - Name of the R2. Do not include 'r2' prefix.
|
|
166
|
-
* @param {string?} options.bindingName - Name of the R2's binding. If not set then it's generated automatically based on the provided name.
|
|
167
|
-
* @returns {sst.cloudflare.Bucket} An instance of Cloudflare R2.
|
|
168
151
|
*/
|
|
169
|
-
r2(
|
|
152
|
+
r2(options: {
|
|
153
|
+
/**
|
|
154
|
+
* Name of the R2. Do not include the 'r2' prefix.
|
|
155
|
+
*/
|
|
170
156
|
resourceName: string;
|
|
157
|
+
/**
|
|
158
|
+
* Name of the R2's binding. If not set, it is generated automatically based on the provided name.
|
|
159
|
+
*/
|
|
171
160
|
bindingName?: string;
|
|
161
|
+
/**
|
|
162
|
+
* The storage class for the R2 bucket.
|
|
163
|
+
*/
|
|
172
164
|
storageClass?: 'Standard' | 'InfrequentAccess';
|
|
173
|
-
}):
|
|
165
|
+
}): any;
|
|
174
166
|
}
|
|
175
167
|
|
|
176
168
|
type InternalErrorResponseStatus = Exclude<StatusCodes, 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207>;
|
package/dist/index.d.ts
CHANGED
|
@@ -30,35 +30,10 @@ type Resource = 'kv' | 'd1' | 'queue' | 'r2' | 'worker' | 'service' | 'orchestra
|
|
|
30
30
|
|
|
31
31
|
type Environment = number | 'dev' | 'test' | 'staging' | 'production';
|
|
32
32
|
|
|
33
|
-
interface
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
interface KvComponent {
|
|
38
|
-
name?: string;
|
|
39
|
-
[key: string]: unknown;
|
|
40
|
-
}
|
|
41
|
-
interface QueueComponent {
|
|
42
|
-
url?: string;
|
|
43
|
-
[key: string]: unknown;
|
|
44
|
-
}
|
|
45
|
-
interface WorkerComponent {
|
|
46
|
-
url?: string;
|
|
47
|
-
[key: string]: unknown;
|
|
48
|
-
}
|
|
49
|
-
interface BucketComponent {
|
|
50
|
-
name?: string;
|
|
51
|
-
[key: string]: unknown;
|
|
52
|
-
}
|
|
53
|
-
interface SSTCloudflare {
|
|
54
|
-
Kv: new (name: string, args?: unknown) => KvComponent;
|
|
55
|
-
Worker: new (name: string, args: unknown) => WorkerComponent;
|
|
56
|
-
Bucket: new (name: string, args?: unknown) => BucketComponent;
|
|
57
|
-
D1: new (name: string, args?: unknown) => D1Component;
|
|
58
|
-
Queue: new (name: string, args?: unknown) => QueueComponent;
|
|
59
|
-
}
|
|
60
|
-
interface SSTContext {
|
|
61
|
-
cloudflare: SSTCloudflare;
|
|
33
|
+
interface SstInstance {
|
|
34
|
+
cloudflare: {
|
|
35
|
+
[key: string]: any;
|
|
36
|
+
};
|
|
62
37
|
}
|
|
63
38
|
declare class Infrastructure {
|
|
64
39
|
private project;
|
|
@@ -67,7 +42,7 @@ declare class Infrastructure {
|
|
|
67
42
|
constructor({ project, environment, sst, }: {
|
|
68
43
|
project: Project;
|
|
69
44
|
environment: Environment;
|
|
70
|
-
sst:
|
|
45
|
+
sst: SstInstance;
|
|
71
46
|
});
|
|
72
47
|
composeBindingName({ resource, resourceName, bindingName, }: {
|
|
73
48
|
resource: Resource;
|
|
@@ -126,51 +101,68 @@ declare class Infrastructure {
|
|
|
126
101
|
};
|
|
127
102
|
/**
|
|
128
103
|
* Creates an instance of Cloudflare KV.
|
|
129
|
-
* @param {Object} options - Configuration options for the KV instance.
|
|
130
|
-
* @param {string} options.name - Name of the KV. Do not include 'kv' prefix.
|
|
131
|
-
* @param {string?} options.bindingName - Name of the KV's binding. If not set then it's generated automatically based on the provided name.
|
|
132
|
-
* @returns {sst.cloudflare.Kv} An instance of Cloudflare KV.
|
|
133
104
|
*/
|
|
134
|
-
kv(
|
|
105
|
+
kv(options: {
|
|
106
|
+
/**
|
|
107
|
+
* Name of the KV. Do not include the 'kv' prefix.
|
|
108
|
+
*/
|
|
135
109
|
resourceName: string;
|
|
110
|
+
/**
|
|
111
|
+
* Name of the KV's binding. If not set, it is generated automatically based on the provided name.
|
|
112
|
+
*/
|
|
136
113
|
bindingName?: string;
|
|
137
|
-
}):
|
|
114
|
+
}): any;
|
|
138
115
|
/**
|
|
139
116
|
* Creates an instance of Cloudflare D1.
|
|
140
|
-
* @param {Object} options - Configuration options for the D1 instance.
|
|
141
|
-
* @param {string} options.name - Name of the D1. Do not include 'd1' prefix.
|
|
142
|
-
* @param {string?} options.bindingName - Name of the D1's binding. If not set then it's generated automatically based on the provided name.
|
|
143
|
-
* @returns {sst.cloudflare.D1} An instance of Cloudflare D1.
|
|
144
117
|
*/
|
|
145
|
-
d1(
|
|
118
|
+
d1(options: {
|
|
119
|
+
/**
|
|
120
|
+
* Name of the D1. Do not include the 'd1' prefix.
|
|
121
|
+
*/
|
|
146
122
|
resourceName: string;
|
|
123
|
+
/**
|
|
124
|
+
* Name of the D1's binding. If not set, it is generated automatically based on the provided name.
|
|
125
|
+
*/
|
|
147
126
|
bindingName?: string;
|
|
148
|
-
}):
|
|
127
|
+
}): any;
|
|
149
128
|
/**
|
|
150
129
|
* Creates an instance of Cloudflare Queue.
|
|
151
|
-
* @param {Object} options - Configuration options for the Queue instance.
|
|
152
|
-
* @param {string} options.name - Name of the Queue. Do not include 'queue' prefix.
|
|
153
|
-
* @param {string?} options.bindingName - Name of the Queue's binding. If not set then it's generated automatically based on the provided name.
|
|
154
|
-
* @returns {sst.cloudflare.Queue} An instance of Cloudflare Queue.
|
|
155
130
|
*/
|
|
156
|
-
queue(
|
|
131
|
+
queue(options: {
|
|
132
|
+
/**
|
|
133
|
+
* Name of the Queue. Do not include the 'queue' prefix.
|
|
134
|
+
*/
|
|
157
135
|
resourceName: string;
|
|
136
|
+
/**
|
|
137
|
+
* Name of the Queue's binding. If not set, it is generated automatically based on the provided name.
|
|
138
|
+
*/
|
|
158
139
|
bindingName?: string;
|
|
140
|
+
/**
|
|
141
|
+
* The number of seconds to delay delivery of messages to the queue.
|
|
142
|
+
*/
|
|
159
143
|
deliveryDelay?: number;
|
|
144
|
+
/**
|
|
145
|
+
* The number of seconds a message will remain in the queue before being deleted.
|
|
146
|
+
*/
|
|
160
147
|
messageRetentionPeriod?: number;
|
|
161
|
-
}):
|
|
148
|
+
}): any;
|
|
162
149
|
/**
|
|
163
150
|
* Creates an instance of Cloudflare R2.
|
|
164
|
-
* @param {Object} options - Configuration options for the R2 instance.
|
|
165
|
-
* @param {string} options.name - Name of the R2. Do not include 'r2' prefix.
|
|
166
|
-
* @param {string?} options.bindingName - Name of the R2's binding. If not set then it's generated automatically based on the provided name.
|
|
167
|
-
* @returns {sst.cloudflare.Bucket} An instance of Cloudflare R2.
|
|
168
151
|
*/
|
|
169
|
-
r2(
|
|
152
|
+
r2(options: {
|
|
153
|
+
/**
|
|
154
|
+
* Name of the R2. Do not include the 'r2' prefix.
|
|
155
|
+
*/
|
|
170
156
|
resourceName: string;
|
|
157
|
+
/**
|
|
158
|
+
* Name of the R2's binding. If not set, it is generated automatically based on the provided name.
|
|
159
|
+
*/
|
|
171
160
|
bindingName?: string;
|
|
161
|
+
/**
|
|
162
|
+
* The storage class for the R2 bucket.
|
|
163
|
+
*/
|
|
172
164
|
storageClass?: 'Standard' | 'InfrequentAccess';
|
|
173
|
-
}):
|
|
165
|
+
}): any;
|
|
174
166
|
}
|
|
175
167
|
|
|
176
168
|
type InternalErrorResponseStatus = Exclude<StatusCodes, 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207>;
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { sql } from 'drizzle-orm';
|
|
2
2
|
import { timestamp, uuid } from 'drizzle-orm/pg-core';
|
|
3
3
|
import { integer, text } from 'drizzle-orm/sqlite-core';
|
|
4
|
+
import { toSnakeCase } from '@std/text';
|
|
4
5
|
import 'http-status-codes';
|
|
5
6
|
import * as z from 'zod/v4/core';
|
|
6
7
|
import { createError } from 'h3';
|
|
@@ -29,37 +30,6 @@ const basePostgres = {
|
|
|
29
30
|
}).default(sql`null`)
|
|
30
31
|
};
|
|
31
32
|
|
|
32
|
-
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
33
|
-
const CAPITALIZED_WORD_REGEXP = /\p{Lu}\p{Ll}+/u; // e.g. Apple
|
|
34
|
-
const ACRONYM_REGEXP = /\p{Lu}+(?=(\p{Lu}\p{Ll})|\P{L}|\b)/u; // e.g. ID, URL, handles an acronym followed by a capitalized word e.g. HTMLElement
|
|
35
|
-
const LOWERCASED_WORD_REGEXP = /(\p{Ll}+)/u; // e.g. apple
|
|
36
|
-
const ANY_LETTERS = /\p{L}+/u; // will match any sequence of letters, including in languages without a concept of upper/lower case
|
|
37
|
-
const DIGITS_REGEXP = /\p{N}+/u; // e.g. 123
|
|
38
|
-
const WORD_OR_NUMBER_REGEXP = new RegExp(`${CAPITALIZED_WORD_REGEXP.source}|${ACRONYM_REGEXP.source}|${LOWERCASED_WORD_REGEXP.source}|${ANY_LETTERS.source}|${DIGITS_REGEXP.source}`, "gu");
|
|
39
|
-
function splitToWords(input) {
|
|
40
|
-
return input.match(WORD_OR_NUMBER_REGEXP) ?? [];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
44
|
-
// This module is browser compatible.
|
|
45
|
-
/**
|
|
46
|
-
* Converts a string into snake_case.
|
|
47
|
-
*
|
|
48
|
-
* @example Usage
|
|
49
|
-
* ```ts
|
|
50
|
-
* import { toSnakeCase } from "@std/text/to-snake-case";
|
|
51
|
-
* import { assertEquals } from "@std/assert";
|
|
52
|
-
*
|
|
53
|
-
* assertEquals(toSnakeCase("deno is awesome"), "deno_is_awesome");
|
|
54
|
-
* ```
|
|
55
|
-
*
|
|
56
|
-
* @param input The string that is going to be converted into snake_case
|
|
57
|
-
* @returns The string as snake_case
|
|
58
|
-
*/ function toSnakeCase(input) {
|
|
59
|
-
input = input.trim();
|
|
60
|
-
return splitToWords(input).join("_").toLowerCase();
|
|
61
|
-
}
|
|
62
|
-
|
|
63
33
|
class Infrastructure {
|
|
64
34
|
project;
|
|
65
35
|
environment;
|
|
@@ -79,7 +49,8 @@ class Infrastructure {
|
|
|
79
49
|
resourceName,
|
|
80
50
|
bindingName
|
|
81
51
|
}) {
|
|
82
|
-
|
|
52
|
+
const convertedBindingName = bindingName ? toSnakeCase(bindingName) : `${toSnakeCase(resourceName)}_${resource}`;
|
|
53
|
+
return convertedBindingName.toUpperCase();
|
|
83
54
|
}
|
|
84
55
|
// TODO(Pookensivee): Make tests for this util
|
|
85
56
|
composeResourceName({ resourceName }) {
|
|
@@ -140,7 +111,7 @@ class Infrastructure {
|
|
|
140
111
|
}
|
|
141
112
|
};
|
|
142
113
|
}
|
|
143
|
-
// TODO: Solve the circular dependency on post
|
|
114
|
+
// TODO: Solve the circular dependency on post infrastructure deploy script
|
|
144
115
|
// TODO: Cannot assign a queue as a producer, work around: https://developers.cloudflare.com/workers/wrangler/commands/#queues-consumer-add-script-name
|
|
145
116
|
// async composeWorkerArguments({
|
|
146
117
|
// resourceName,
|
|
@@ -199,6 +170,7 @@ class Infrastructure {
|
|
|
199
170
|
// join(path, './wrangler.jsonc'),
|
|
200
171
|
// 'utf-8',
|
|
201
172
|
// )
|
|
173
|
+
// TODO: Use parse from comment-json
|
|
202
174
|
// const jsonString = workerConfigFile
|
|
203
175
|
// .replace(/\/\*[\s\S]*?\*\//g, '')
|
|
204
176
|
// .replace(/\/\/.*$/gm, '')
|
|
@@ -216,15 +188,9 @@ class Infrastructure {
|
|
|
216
188
|
// }
|
|
217
189
|
/**
|
|
218
190
|
* Creates an instance of Cloudflare KV.
|
|
219
|
-
* @param {Object} options - Configuration options for the KV instance.
|
|
220
|
-
* @param {string} options.name - Name of the KV. Do not include 'kv' prefix.
|
|
221
|
-
* @param {string?} options.bindingName - Name of the KV's binding. If not set then it's generated automatically based on the provided name.
|
|
222
|
-
* @returns {sst.cloudflare.Kv} An instance of Cloudflare KV.
|
|
223
191
|
*/
|
|
224
|
-
kv({
|
|
225
|
-
resourceName,
|
|
226
|
-
bindingName
|
|
227
|
-
}) {
|
|
192
|
+
kv(options) {
|
|
193
|
+
const { resourceName, bindingName } = options;
|
|
228
194
|
return new this.sst.cloudflare.Kv(
|
|
229
195
|
`${this.composeBindingName({ resource: "kv", resourceName, bindingName })}`,
|
|
230
196
|
this.composeKvArguments({
|
|
@@ -234,15 +200,9 @@ class Infrastructure {
|
|
|
234
200
|
}
|
|
235
201
|
/**
|
|
236
202
|
* Creates an instance of Cloudflare D1.
|
|
237
|
-
* @param {Object} options - Configuration options for the D1 instance.
|
|
238
|
-
* @param {string} options.name - Name of the D1. Do not include 'd1' prefix.
|
|
239
|
-
* @param {string?} options.bindingName - Name of the D1's binding. If not set then it's generated automatically based on the provided name.
|
|
240
|
-
* @returns {sst.cloudflare.D1} An instance of Cloudflare D1.
|
|
241
203
|
*/
|
|
242
|
-
d1({
|
|
243
|
-
resourceName,
|
|
244
|
-
bindingName
|
|
245
|
-
}) {
|
|
204
|
+
d1(options) {
|
|
205
|
+
const { resourceName, bindingName } = options;
|
|
246
206
|
return new this.sst.cloudflare.D1(
|
|
247
207
|
`${this.composeBindingName({ resource: "d1", resourceName, bindingName })}`,
|
|
248
208
|
this.composeD1Arguments({
|
|
@@ -252,17 +212,9 @@ class Infrastructure {
|
|
|
252
212
|
}
|
|
253
213
|
/**
|
|
254
214
|
* Creates an instance of Cloudflare Queue.
|
|
255
|
-
* @param {Object} options - Configuration options for the Queue instance.
|
|
256
|
-
* @param {string} options.name - Name of the Queue. Do not include 'queue' prefix.
|
|
257
|
-
* @param {string?} options.bindingName - Name of the Queue's binding. If not set then it's generated automatically based on the provided name.
|
|
258
|
-
* @returns {sst.cloudflare.Queue} An instance of Cloudflare Queue.
|
|
259
215
|
*/
|
|
260
|
-
queue({
|
|
261
|
-
resourceName,
|
|
262
|
-
bindingName,
|
|
263
|
-
deliveryDelay,
|
|
264
|
-
messageRetentionPeriod
|
|
265
|
-
}) {
|
|
216
|
+
queue(options) {
|
|
217
|
+
const { resourceName, bindingName, deliveryDelay, messageRetentionPeriod } = options;
|
|
266
218
|
return new this.sst.cloudflare.Queue(
|
|
267
219
|
`${this.composeBindingName({ resource: "queue", resourceName, bindingName })}`,
|
|
268
220
|
this.composeQueueArguments({
|
|
@@ -274,16 +226,9 @@ class Infrastructure {
|
|
|
274
226
|
}
|
|
275
227
|
/**
|
|
276
228
|
* Creates an instance of Cloudflare R2.
|
|
277
|
-
* @param {Object} options - Configuration options for the R2 instance.
|
|
278
|
-
* @param {string} options.name - Name of the R2. Do not include 'r2' prefix.
|
|
279
|
-
* @param {string?} options.bindingName - Name of the R2's binding. If not set then it's generated automatically based on the provided name.
|
|
280
|
-
* @returns {sst.cloudflare.Bucket} An instance of Cloudflare R2.
|
|
281
229
|
*/
|
|
282
|
-
r2({
|
|
283
|
-
resourceName,
|
|
284
|
-
bindingName,
|
|
285
|
-
storageClass
|
|
286
|
-
}) {
|
|
230
|
+
r2(options) {
|
|
231
|
+
const { resourceName, bindingName, storageClass } = options;
|
|
287
232
|
return new this.sst.cloudflare.Bucket(
|
|
288
233
|
`${this.composeBindingName({ resource: "r2", resourceName, bindingName })}`,
|
|
289
234
|
this.composeR2Arguments({
|
|
@@ -292,6 +237,7 @@ class Infrastructure {
|
|
|
292
237
|
})
|
|
293
238
|
);
|
|
294
239
|
}
|
|
240
|
+
// TODO: Solve the circular dependency on post infrastructure deploy script
|
|
295
241
|
// async worker({
|
|
296
242
|
// resourceName,
|
|
297
243
|
// bindingName,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@develit-io/backend-sdk",
|
|
3
|
-
"version": "5.14.
|
|
3
|
+
"version": "5.14.1",
|
|
4
4
|
"description": "Develit Backend SDK",
|
|
5
5
|
"author": "Develit.io",
|
|
6
6
|
"license": "ISC",
|
|
@@ -30,7 +30,10 @@
|
|
|
30
30
|
"dist"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@cloudflare/workers-types": "
|
|
33
|
+
"@cloudflare/workers-types": "4.20250909.0",
|
|
34
|
+
"@pulumi/cloudflare": "^6.8.0",
|
|
35
|
+
"@std/path": "npm:@jsr/std__path",
|
|
36
|
+
"@std/text": "npm:@jsr/std__text",
|
|
34
37
|
"comment-json": "^4.2.5",
|
|
35
38
|
"consola": "^3.4.2",
|
|
36
39
|
"drizzle-kit": "^0.31.4",
|
|
@@ -42,9 +45,5 @@
|
|
|
42
45
|
"peerDependencies": {
|
|
43
46
|
"sst": "^3.17.12",
|
|
44
47
|
"zod": "^4.1.5"
|
|
45
|
-
},
|
|
46
|
-
"devDependencies": {
|
|
47
|
-
"@cloudflare/workers-types": "4.20250909.0",
|
|
48
|
-
"@pulumi/cloudflare": "^6.8.0"
|
|
49
48
|
}
|
|
50
49
|
}
|