@develit-io/backend-sdk 5.21.3 → 5.21.5

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.
@@ -0,0 +1,157 @@
1
+ import { toSnakeCase } from '@std/text';
2
+ import { KVNamespace, D1Database, Queue, R2Bucket } from 'alchemy/cloudflare';
3
+ import { E as ENVIRONMENT } from '../shared/backend-sdk.DXRpnctc.mjs';
4
+
5
+ const composeD1Arguments = ({
6
+ resourceName
7
+ }) => {
8
+ return {
9
+ name: resourceName,
10
+ primaryLocationHint: "weur"
11
+ // TODO: It's possible that it will take care of migrations as well
12
+ };
13
+ };
14
+
15
+ const composeKvArguments = ({
16
+ resourceName
17
+ }) => {
18
+ return {
19
+ title: resourceName
20
+ };
21
+ };
22
+
23
+ const composeQueueArguments = ({
24
+ resourceName,
25
+ deliveryDelay = 5,
26
+ messageRetentionPeriod = 259200
27
+ }) => {
28
+ return {
29
+ name: resourceName,
30
+ settings: {
31
+ deliveryDelay,
32
+ messageRetentionPeriod
33
+ }
34
+ };
35
+ };
36
+
37
+ const composeR2Arguments = ({
38
+ resourceName,
39
+ storageClass = "Standard"
40
+ }) => {
41
+ return {
42
+ name: resourceName,
43
+ jurisdiction: "eu",
44
+ locationHint: "weur",
45
+ storageClass
46
+ };
47
+ };
48
+
49
+ const composeBindingName = ({
50
+ resource,
51
+ resourceName,
52
+ bindingName
53
+ }) => {
54
+ const convertedBindingName = bindingName ? toSnakeCase(bindingName) : `${toSnakeCase(resourceName)}_${resource}`;
55
+ return convertedBindingName.toUpperCase();
56
+ };
57
+ const composeIdentifierName = ({
58
+ resource,
59
+ resourceName
60
+ }) => {
61
+ return `${resourceName}-${resource}`;
62
+ };
63
+ const composeResourceName = ({
64
+ project,
65
+ environment,
66
+ resourceName
67
+ }) => {
68
+ return `${project}-${resourceName}-${environment}`;
69
+ };
70
+
71
+ class Infrastructure {
72
+ project;
73
+ environment;
74
+ constructor({
75
+ project,
76
+ environment
77
+ }) {
78
+ this.project = project;
79
+ this.environment = environment;
80
+ }
81
+ /**
82
+ * Creates an instance of Cloudflare KV.
83
+ */
84
+ async kv(options) {
85
+ const { resourceName } = options;
86
+ return await KVNamespace(
87
+ composeIdentifierName({ resourceName, resource: "kv" }),
88
+ composeKvArguments({
89
+ resourceName: composeResourceName({
90
+ project: this.project,
91
+ environment: this.environment,
92
+ resourceName
93
+ })
94
+ })
95
+ );
96
+ }
97
+ /**
98
+ * Creates an instance of Cloudflare D1.
99
+ */
100
+ async d1(options) {
101
+ const { resourceName } = options;
102
+ return await D1Database(
103
+ composeIdentifierName({ resourceName, resource: "d1" }),
104
+ composeD1Arguments({
105
+ resourceName: composeResourceName({
106
+ project: this.project,
107
+ environment: this.environment,
108
+ resourceName
109
+ })
110
+ })
111
+ );
112
+ }
113
+ /**
114
+ * Creates an instance of Cloudflare Queue.
115
+ */
116
+ async queue(options) {
117
+ const { resourceName, deliveryDelay, messageRetentionPeriod } = options;
118
+ return await Queue(
119
+ composeIdentifierName({ resourceName, resource: "queue" }),
120
+ composeQueueArguments({
121
+ resourceName: composeResourceName({
122
+ project: this.project,
123
+ environment: this.environment,
124
+ resourceName
125
+ }),
126
+ deliveryDelay,
127
+ messageRetentionPeriod
128
+ })
129
+ );
130
+ }
131
+ /**
132
+ * Creates an instance of Cloudflare R2.
133
+ */
134
+ async r2(options) {
135
+ const { resourceName, storageClass } = options;
136
+ return await R2Bucket(
137
+ composeIdentifierName({ resourceName, resource: "r2" }),
138
+ composeR2Arguments({
139
+ resourceName: composeResourceName({
140
+ project: this.project,
141
+ environment: this.environment,
142
+ resourceName
143
+ }),
144
+ storageClass
145
+ })
146
+ );
147
+ }
148
+ }
149
+
150
+ const validateEnvironment = (environment) => {
151
+ if (ENVIRONMENT.includes(environment)) {
152
+ return environment;
153
+ }
154
+ return Number(environment);
155
+ };
156
+
157
+ export { Infrastructure, composeBindingName, composeD1Arguments, composeIdentifierName, composeKvArguments, composeQueueArguments, composeR2Arguments, composeResourceName, validateEnvironment };
@@ -0,0 +1,5 @@
1
+ type Environment = number | 'dev' | 'test' | 'staging' | 'production';
2
+
3
+ type Project = 'creditio' | 'fp' | 'mdm' | 'moneio' | 'txs';
4
+
5
+ export type { Environment as E, Project as P };
@@ -0,0 +1,5 @@
1
+ type Environment = number | 'dev' | 'test' | 'staging' | 'production';
2
+
3
+ type Project = 'creditio' | 'fp' | 'mdm' | 'moneio' | 'txs';
4
+
5
+ export type { Environment as E, Project as P };
@@ -0,0 +1,5 @@
1
+ type Environment = number | 'dev' | 'test' | 'staging' | 'production';
2
+
3
+ type Project = 'creditio' | 'fp' | 'mdm' | 'moneio' | 'txs';
4
+
5
+ export type { Environment as E, Project as P };
@@ -0,0 +1,5 @@
1
+ 'use strict';
2
+
3
+ const ENVIRONMENT = ["dev", "test", "staging", "production"];
4
+
5
+ exports.ENVIRONMENT = ENVIRONMENT;
@@ -0,0 +1,3 @@
1
+ const ENVIRONMENT = ["dev", "test", "staging", "production"];
2
+
3
+ export { ENVIRONMENT as E };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@develit-io/backend-sdk",
3
- "version": "5.21.3",
3
+ "version": "5.21.5",
4
4
  "description": "Develit Backend SDK",
5
5
  "author": "Develit.io",
6
6
  "license": "ISC",
@@ -22,6 +22,11 @@
22
22
  "import": "./dist/index.mjs",
23
23
  "require": "./dist/index.cjs"
24
24
  },
25
+ "./infrastructure": {
26
+ "types": "./dist/infrastructure/index.d.ts",
27
+ "import": "./dist/infrastructure/index.mjs",
28
+ "require": "./dist/infrastructure/index.cjs"
29
+ },
25
30
  "./node": {
26
31
  "types": "./dist/node/index.d.ts",
27
32
  "import": "./dist/node/index.mjs",
@@ -36,7 +41,6 @@
36
41
  "@cloudflare/workers-types": "4.20250923.0",
37
42
  "@std/path": "npm:@jsr/std__path",
38
43
  "@std/text": "npm:@jsr/std__text",
39
- "alchemy": "^0.69.0",
40
44
  "comment-json": "^4.2.5",
41
45
  "drizzle-kit": "^0.31.4",
42
46
  "drizzle-orm": "^0.44.5",
@@ -45,8 +49,8 @@
45
49
  "superjson": "^2.2.2"
46
50
  },
47
51
  "peerDependencies": {
48
- "sst": "^3.17.13",
49
- "zod": "^4.1.8",
50
- "@develit-io/general-codes": "^1.12.1"
52
+ "@develit-io/general-codes": "^1.12.1",
53
+ "alchemy": "^0.69.0",
54
+ "zod": "^4.1.8"
51
55
  }
52
56
  }