@develit-io/backend-sdk 5.21.4 → 5.22.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.
package/dist/index.mjs CHANGED
@@ -2,8 +2,7 @@ import { sql } from 'drizzle-orm';
2
2
  import { timestamp, uuid, pgEnum, text as text$1 } from 'drizzle-orm/pg-core';
3
3
  import { integer, text } from 'drizzle-orm/sqlite-core';
4
4
  import { COUNTRY_CODES_2, CURRENCY_CODES, BANK_CODES } from '@develit-io/general-codes';
5
- import { toSnakeCase } from '@std/text';
6
- import { KVNamespace, D1Database, Queue, R2Bucket } from 'alchemy/cloudflare';
5
+ export { E as ENVIRONMENT } from './shared/backend-sdk.DXRpnctc.mjs';
7
6
  import * as z from 'zod/v4/core';
8
7
  import 'http-status-codes';
9
8
  import { createError } from 'h3';
@@ -56,160 +55,6 @@ const bankAccountPostgres = {
56
55
  countryCode: bankAccountCountryCodeEnum().$type().notNull()
57
56
  };
58
57
 
59
- const composeD1Arguments = ({
60
- resourceName
61
- }) => {
62
- return {
63
- name: resourceName,
64
- primaryLocationHint: "weur"
65
- // TODO: It's possible that it will take care of migrations as well
66
- };
67
- };
68
-
69
- const composeKvArguments = ({
70
- resourceName
71
- }) => {
72
- return {
73
- title: resourceName
74
- };
75
- };
76
-
77
- const composeQueueArguments = ({
78
- resourceName,
79
- deliveryDelay = 5,
80
- messageRetentionPeriod = 259200
81
- }) => {
82
- return {
83
- name: resourceName,
84
- settings: {
85
- deliveryDelay,
86
- messageRetentionPeriod
87
- }
88
- };
89
- };
90
-
91
- const composeR2Arguments = ({
92
- resourceName,
93
- storageClass = "Standard"
94
- }) => {
95
- return {
96
- name: resourceName,
97
- jurisdiction: "eu",
98
- locationHint: "weur",
99
- storageClass
100
- };
101
- };
102
-
103
- const composeBindingName = ({
104
- resource,
105
- resourceName,
106
- bindingName
107
- }) => {
108
- const convertedBindingName = bindingName ? toSnakeCase(bindingName) : `${toSnakeCase(resourceName)}_${resource}`;
109
- return convertedBindingName.toUpperCase();
110
- };
111
- const composeIdentifierName = ({
112
- resource,
113
- resourceName
114
- }) => {
115
- return `${resourceName}-${resource}`;
116
- };
117
- const composeResourceName = ({
118
- project,
119
- environment,
120
- resourceName
121
- }) => {
122
- return `${project}-${resourceName}-${environment}`;
123
- };
124
-
125
- class Infrastructure {
126
- project;
127
- environment;
128
- constructor({
129
- project,
130
- environment
131
- }) {
132
- this.project = project;
133
- this.environment = environment;
134
- }
135
- /**
136
- * Creates an instance of Cloudflare KV.
137
- */
138
- async kv(options) {
139
- const { resourceName } = options;
140
- return await KVNamespace(
141
- composeIdentifierName({ resourceName, resource: "kv" }),
142
- composeKvArguments({
143
- resourceName: composeResourceName({
144
- project: this.project,
145
- environment: this.environment,
146
- resourceName
147
- })
148
- })
149
- );
150
- }
151
- /**
152
- * Creates an instance of Cloudflare D1.
153
- */
154
- async d1(options) {
155
- const { resourceName } = options;
156
- return await D1Database(
157
- composeIdentifierName({ resourceName, resource: "d1" }),
158
- composeD1Arguments({
159
- resourceName: composeResourceName({
160
- project: this.project,
161
- environment: this.environment,
162
- resourceName
163
- })
164
- })
165
- );
166
- }
167
- /**
168
- * Creates an instance of Cloudflare Queue.
169
- */
170
- async queue(options) {
171
- const { resourceName, deliveryDelay, messageRetentionPeriod } = options;
172
- return await Queue(
173
- composeIdentifierName({ resourceName, resource: "queue" }),
174
- composeQueueArguments({
175
- resourceName: composeResourceName({
176
- project: this.project,
177
- environment: this.environment,
178
- resourceName
179
- }),
180
- deliveryDelay,
181
- messageRetentionPeriod
182
- })
183
- );
184
- }
185
- /**
186
- * Creates an instance of Cloudflare R2.
187
- */
188
- async r2(options) {
189
- const { resourceName, storageClass } = options;
190
- return await R2Bucket(
191
- composeIdentifierName({ resourceName, resource: "r2" }),
192
- composeR2Arguments({
193
- resourceName: composeResourceName({
194
- project: this.project,
195
- environment: this.environment,
196
- resourceName
197
- }),
198
- storageClass
199
- })
200
- );
201
- }
202
- }
203
-
204
- const ENVIRONMENT = ["dev", "test", "staging", "production"];
205
-
206
- const validateEnvironment = (environment) => {
207
- if (ENVIRONMENT.includes(environment)) {
208
- return environment;
209
- }
210
- return Number(environment);
211
- };
212
-
213
58
  const ibanZodSchema = new z.$ZodString({
214
59
  type: "string",
215
60
  checks: [
@@ -874,4 +719,4 @@ function develitWorker(Worker) {
874
719
  return DevelitWorker;
875
720
  }
876
721
 
877
- export { DatabaseTransaction, ENVIRONMENT, Infrastructure, RPCResponse, action, bankAccount, bankAccountBankCodeEnum, bankAccountCountryCodeEnum, bankAccountCurrencyEnum, bankAccountPostgres, base, basePostgres, calculateExponentialBackoff, cloudflareQueue, composeBindingName, createAuditLogWriter, createInternalError, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getDrizzlePgConfig, getPgCredentials, getPgDatabaseIdFromWrangler, getPgLocalConnectionString, handleAction, handleActionResponse, ibanZodSchema, isInternalError, paginationQuerySchema, paginationSchema, service, swiftZodSchema, useFetch, useResult, useResultSync, uuidv4, validateEnvironment };
722
+ export { DatabaseTransaction, RPCResponse, action, bankAccount, bankAccountBankCodeEnum, bankAccountCountryCodeEnum, bankAccountCurrencyEnum, bankAccountPostgres, base, basePostgres, calculateExponentialBackoff, cloudflareQueue, createAuditLogWriter, createInternalError, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getDrizzlePgConfig, getPgCredentials, getPgDatabaseIdFromWrangler, getPgLocalConnectionString, handleAction, handleActionResponse, ibanZodSchema, isInternalError, paginationQuerySchema, paginationSchema, service, swiftZodSchema, useFetch, useResult, useResultSync, uuidv4 };
@@ -0,0 +1,193 @@
1
+ 'use strict';
2
+
3
+ const node_index = require('../shared/backend-sdk.CpwGFVDb.cjs');
4
+ const cloudflare = require('alchemy/cloudflare');
5
+ const environment_consts = require('../shared/backend-sdk.BdcrYpFD.cjs');
6
+
7
+ const composeD1Arguments = ({
8
+ resourceName
9
+ }) => {
10
+ return {
11
+ name: resourceName,
12
+ primaryLocationHint: node_index.D1_LOCATION_HINT
13
+ };
14
+ };
15
+
16
+ const composeKvArguments = ({
17
+ resourceName
18
+ }) => {
19
+ return {
20
+ title: resourceName
21
+ };
22
+ };
23
+
24
+ const composeQueueArguments = ({
25
+ resourceName,
26
+ deliveryDelay = node_index.QUEUE_DELIVERY_DELAY,
27
+ messageRetentionPeriod = node_index.QUEUE_MESSAGE_RETENTION_PERIOD
28
+ }) => {
29
+ return {
30
+ name: resourceName,
31
+ settings: {
32
+ deliveryDelay,
33
+ messageRetentionPeriod
34
+ }
35
+ };
36
+ };
37
+
38
+ const composeR2Arguments = ({
39
+ resourceName,
40
+ storageClass = node_index.R2_STORAGE_CLASS
41
+ }) => {
42
+ return {
43
+ name: resourceName,
44
+ jurisdiction: node_index.R2_JURISDICTION,
45
+ locationHint: node_index.R2_LOCATION_HINT,
46
+ storageClass
47
+ };
48
+ };
49
+
50
+ const composeIdentifierName = ({
51
+ resource,
52
+ resourceName
53
+ }) => {
54
+ return `${resourceName}-${resource}`;
55
+ };
56
+ const composeResourceName = ({
57
+ project,
58
+ environment,
59
+ resourceName
60
+ }) => {
61
+ return `${project}-${resourceName}-${environment}`;
62
+ };
63
+
64
+ class Infrastructure {
65
+ project;
66
+ environment;
67
+ constructor({
68
+ project,
69
+ environment
70
+ }) {
71
+ this.project = project;
72
+ this.environment = environment;
73
+ }
74
+ /**
75
+ * Creates an instance of Cloudflare KV.
76
+ */
77
+ async kv(options) {
78
+ const { resourceName } = options;
79
+ return await cloudflare.KVNamespace(
80
+ composeIdentifierName({ resourceName, resource: "kv" }),
81
+ composeKvArguments({
82
+ resourceName: composeResourceName({
83
+ project: this.project,
84
+ environment: this.environment,
85
+ resourceName
86
+ })
87
+ })
88
+ );
89
+ }
90
+ /**
91
+ * Creates an instance of Cloudflare D1.
92
+ */
93
+ async d1(options) {
94
+ const { resourceName } = options;
95
+ return await cloudflare.D1Database(
96
+ composeIdentifierName({ resourceName, resource: "d1" }),
97
+ composeD1Arguments({
98
+ resourceName: composeResourceName({
99
+ project: this.project,
100
+ environment: this.environment,
101
+ resourceName
102
+ })
103
+ })
104
+ );
105
+ }
106
+ /**
107
+ * Creates an instance of Cloudflare Queue.
108
+ */
109
+ async queue(options) {
110
+ const { resourceName, deliveryDelay, messageRetentionPeriod } = options;
111
+ return await cloudflare.Queue(
112
+ composeIdentifierName({ resourceName, resource: "queue" }),
113
+ composeQueueArguments({
114
+ resourceName: composeResourceName({
115
+ project: this.project,
116
+ environment: this.environment,
117
+ resourceName
118
+ }),
119
+ deliveryDelay,
120
+ messageRetentionPeriod
121
+ })
122
+ );
123
+ }
124
+ /**
125
+ * Creates an instance of Cloudflare R2.
126
+ */
127
+ async r2(options) {
128
+ const { resourceName, storageClass } = options;
129
+ return await cloudflare.R2Bucket(
130
+ composeIdentifierName({ resourceName, resource: "r2" }),
131
+ composeR2Arguments({
132
+ resourceName: composeResourceName({
133
+ project: this.project,
134
+ environment: this.environment,
135
+ resourceName
136
+ }),
137
+ storageClass
138
+ })
139
+ );
140
+ }
141
+ /**
142
+ * Creates an instance of Cloudflare Worker.
143
+ */
144
+ async worker(options) {
145
+ const { resourceName, entrypoint, bindings, eventSources } = options;
146
+ const identifierName = composeIdentifierName({
147
+ resourceName,
148
+ resource: "worker"
149
+ });
150
+ return await cloudflare.Worker(
151
+ identifierName,
152
+ node_index.composeWorkerArguments({
153
+ resourceName: composeResourceName({
154
+ project: this.project,
155
+ environment: this.environment,
156
+ resourceName: identifierName
157
+ }),
158
+ entrypoint,
159
+ bindings,
160
+ eventSources
161
+ })
162
+ );
163
+ }
164
+ /**
165
+ * Creates an instance of Cloudflare Worker as a service.
166
+ */
167
+ async service(options) {
168
+ const { resourceName, bindings, eventSources } = options;
169
+ return await this.worker({
170
+ resourceName,
171
+ // TODO: Convert to util
172
+ entrypoint: `./services/${resourceName}/src/index.ts`,
173
+ bindings,
174
+ eventSources
175
+ });
176
+ }
177
+ }
178
+
179
+ const validateEnvironment = (environment) => {
180
+ if (environment_consts.ENVIRONMENT.includes(environment)) {
181
+ return environment;
182
+ }
183
+ return Number(environment);
184
+ };
185
+
186
+ exports.Infrastructure = Infrastructure;
187
+ exports.composeD1Arguments = composeD1Arguments;
188
+ exports.composeIdentifierName = composeIdentifierName;
189
+ exports.composeKvArguments = composeKvArguments;
190
+ exports.composeQueueArguments = composeQueueArguments;
191
+ exports.composeR2Arguments = composeR2Arguments;
192
+ exports.composeResourceName = composeResourceName;
193
+ exports.validateEnvironment = validateEnvironment;
@@ -0,0 +1,148 @@
1
+ import { P as Project, E as Environment } from '../shared/backend-sdk._l2mbzzF.cjs';
2
+ import { KVNamespace, D1Database, Queue, R2Bucket, Bindings, Worker } from 'alchemy/cloudflare';
3
+
4
+ type Resource = 'kv' | 'd1' | 'queue' | 'r2' | 'worker' | 'service' | 'orchestrator';
5
+
6
+ declare class Infrastructure {
7
+ private project;
8
+ private environment;
9
+ constructor({ project, environment, }: {
10
+ project: Project;
11
+ environment: Environment;
12
+ });
13
+ /**
14
+ * Creates an instance of Cloudflare KV.
15
+ */
16
+ kv(options: {
17
+ /**
18
+ * Name of the KV. Do not include the 'kv' prefix.
19
+ */
20
+ resourceName: string;
21
+ }): Promise<KVNamespace>;
22
+ /**
23
+ * Creates an instance of Cloudflare D1.
24
+ */
25
+ d1(options: {
26
+ /**
27
+ * Name of the D1. Do not include the 'd1' prefix.
28
+ */
29
+ resourceName: string;
30
+ }): Promise<D1Database>;
31
+ /**
32
+ * Creates an instance of Cloudflare Queue.
33
+ */
34
+ queue(options: {
35
+ /**
36
+ * Name of the Queue. Do not include the 'queue' prefix.
37
+ */
38
+ resourceName: string;
39
+ /**
40
+ * The number of seconds to delay delivery of messages to the queue.
41
+ */
42
+ deliveryDelay?: number;
43
+ /**
44
+ * The number of seconds a message will remain in the queue before being deleted.
45
+ */
46
+ messageRetentionPeriod?: number;
47
+ }): Promise<Queue<unknown>>;
48
+ /**
49
+ * Creates an instance of Cloudflare R2.
50
+ */
51
+ r2(options: {
52
+ /**
53
+ * Name of the R2. Do not include the 'r2' prefix.
54
+ */
55
+ resourceName: string;
56
+ /**
57
+ * The storage class for the R2 bucket.
58
+ */
59
+ storageClass?: 'Standard' | 'InfrequentAccess';
60
+ }): Promise<R2Bucket>;
61
+ /**
62
+ * Creates an instance of Cloudflare Worker.
63
+ */
64
+ worker(options: {
65
+ /**
66
+ * Name of the Worker. Do not include the 'worker' prefix.
67
+ */
68
+ resourceName: string;
69
+ /**
70
+ * Entrypoint file of the Worker.
71
+ */
72
+ entrypoint: string;
73
+ /**
74
+ * Bindings of the Worker.
75
+ */
76
+ bindings: Bindings;
77
+ /**
78
+ * Event sources for the service to consume.
79
+ */
80
+ eventSources?: Queue[];
81
+ }): Promise<Worker<Bindings, Rpc.WorkerEntrypointBranded>>;
82
+ /**
83
+ * Creates an instance of Cloudflare Worker as a service.
84
+ */
85
+ service(options: {
86
+ /**
87
+ * Name of the service. Do not include the 'service' prefix.
88
+ */
89
+ resourceName: string;
90
+ /**
91
+ * Bindings of the Worker.
92
+ */
93
+ bindings: Bindings;
94
+ /**
95
+ * Event sources for the service to consume.
96
+ */
97
+ eventSources?: Queue[];
98
+ }): Promise<Worker<Bindings, Rpc.WorkerEntrypointBranded>>;
99
+ }
100
+
101
+ declare const composeD1Arguments: ({ resourceName, }: {
102
+ resourceName: string;
103
+ }) => {
104
+ name: string;
105
+ primaryLocationHint: "weur";
106
+ };
107
+
108
+ declare const composeKvArguments: ({ resourceName, }: {
109
+ resourceName: string;
110
+ }) => {
111
+ title: string;
112
+ };
113
+
114
+ declare const composeQueueArguments: ({ resourceName, deliveryDelay, messageRetentionPeriod, }: {
115
+ resourceName: string;
116
+ deliveryDelay?: number;
117
+ messageRetentionPeriod?: number;
118
+ }) => {
119
+ name: string;
120
+ settings: {
121
+ deliveryDelay: number;
122
+ messageRetentionPeriod: number;
123
+ };
124
+ };
125
+
126
+ declare const composeR2Arguments: ({ resourceName, storageClass, }: {
127
+ resourceName: string;
128
+ storageClass?: "Standard" | "InfrequentAccess";
129
+ }) => {
130
+ name: string;
131
+ jurisdiction: "eu";
132
+ locationHint: string;
133
+ storageClass: "Standard" | "InfrequentAccess";
134
+ };
135
+
136
+ declare const composeIdentifierName: ({ resource, resourceName, }: {
137
+ resource: Resource;
138
+ resourceName: string;
139
+ }) => string;
140
+ declare const composeResourceName: ({ project, environment, resourceName, }: {
141
+ project: Project;
142
+ environment: Environment;
143
+ resourceName: string;
144
+ }) => string;
145
+
146
+ declare const validateEnvironment: (environment: string) => Environment;
147
+
148
+ export { Infrastructure, composeD1Arguments, composeIdentifierName, composeKvArguments, composeQueueArguments, composeR2Arguments, composeResourceName, validateEnvironment };
@@ -0,0 +1,148 @@
1
+ import { P as Project, E as Environment } from '../shared/backend-sdk._l2mbzzF.mjs';
2
+ import { KVNamespace, D1Database, Queue, R2Bucket, Bindings, Worker } from 'alchemy/cloudflare';
3
+
4
+ type Resource = 'kv' | 'd1' | 'queue' | 'r2' | 'worker' | 'service' | 'orchestrator';
5
+
6
+ declare class Infrastructure {
7
+ private project;
8
+ private environment;
9
+ constructor({ project, environment, }: {
10
+ project: Project;
11
+ environment: Environment;
12
+ });
13
+ /**
14
+ * Creates an instance of Cloudflare KV.
15
+ */
16
+ kv(options: {
17
+ /**
18
+ * Name of the KV. Do not include the 'kv' prefix.
19
+ */
20
+ resourceName: string;
21
+ }): Promise<KVNamespace>;
22
+ /**
23
+ * Creates an instance of Cloudflare D1.
24
+ */
25
+ d1(options: {
26
+ /**
27
+ * Name of the D1. Do not include the 'd1' prefix.
28
+ */
29
+ resourceName: string;
30
+ }): Promise<D1Database>;
31
+ /**
32
+ * Creates an instance of Cloudflare Queue.
33
+ */
34
+ queue(options: {
35
+ /**
36
+ * Name of the Queue. Do not include the 'queue' prefix.
37
+ */
38
+ resourceName: string;
39
+ /**
40
+ * The number of seconds to delay delivery of messages to the queue.
41
+ */
42
+ deliveryDelay?: number;
43
+ /**
44
+ * The number of seconds a message will remain in the queue before being deleted.
45
+ */
46
+ messageRetentionPeriod?: number;
47
+ }): Promise<Queue<unknown>>;
48
+ /**
49
+ * Creates an instance of Cloudflare R2.
50
+ */
51
+ r2(options: {
52
+ /**
53
+ * Name of the R2. Do not include the 'r2' prefix.
54
+ */
55
+ resourceName: string;
56
+ /**
57
+ * The storage class for the R2 bucket.
58
+ */
59
+ storageClass?: 'Standard' | 'InfrequentAccess';
60
+ }): Promise<R2Bucket>;
61
+ /**
62
+ * Creates an instance of Cloudflare Worker.
63
+ */
64
+ worker(options: {
65
+ /**
66
+ * Name of the Worker. Do not include the 'worker' prefix.
67
+ */
68
+ resourceName: string;
69
+ /**
70
+ * Entrypoint file of the Worker.
71
+ */
72
+ entrypoint: string;
73
+ /**
74
+ * Bindings of the Worker.
75
+ */
76
+ bindings: Bindings;
77
+ /**
78
+ * Event sources for the service to consume.
79
+ */
80
+ eventSources?: Queue[];
81
+ }): Promise<Worker<Bindings, Rpc.WorkerEntrypointBranded>>;
82
+ /**
83
+ * Creates an instance of Cloudflare Worker as a service.
84
+ */
85
+ service(options: {
86
+ /**
87
+ * Name of the service. Do not include the 'service' prefix.
88
+ */
89
+ resourceName: string;
90
+ /**
91
+ * Bindings of the Worker.
92
+ */
93
+ bindings: Bindings;
94
+ /**
95
+ * Event sources for the service to consume.
96
+ */
97
+ eventSources?: Queue[];
98
+ }): Promise<Worker<Bindings, Rpc.WorkerEntrypointBranded>>;
99
+ }
100
+
101
+ declare const composeD1Arguments: ({ resourceName, }: {
102
+ resourceName: string;
103
+ }) => {
104
+ name: string;
105
+ primaryLocationHint: "weur";
106
+ };
107
+
108
+ declare const composeKvArguments: ({ resourceName, }: {
109
+ resourceName: string;
110
+ }) => {
111
+ title: string;
112
+ };
113
+
114
+ declare const composeQueueArguments: ({ resourceName, deliveryDelay, messageRetentionPeriod, }: {
115
+ resourceName: string;
116
+ deliveryDelay?: number;
117
+ messageRetentionPeriod?: number;
118
+ }) => {
119
+ name: string;
120
+ settings: {
121
+ deliveryDelay: number;
122
+ messageRetentionPeriod: number;
123
+ };
124
+ };
125
+
126
+ declare const composeR2Arguments: ({ resourceName, storageClass, }: {
127
+ resourceName: string;
128
+ storageClass?: "Standard" | "InfrequentAccess";
129
+ }) => {
130
+ name: string;
131
+ jurisdiction: "eu";
132
+ locationHint: string;
133
+ storageClass: "Standard" | "InfrequentAccess";
134
+ };
135
+
136
+ declare const composeIdentifierName: ({ resource, resourceName, }: {
137
+ resource: Resource;
138
+ resourceName: string;
139
+ }) => string;
140
+ declare const composeResourceName: ({ project, environment, resourceName, }: {
141
+ project: Project;
142
+ environment: Environment;
143
+ resourceName: string;
144
+ }) => string;
145
+
146
+ declare const validateEnvironment: (environment: string) => Environment;
147
+
148
+ export { Infrastructure, composeD1Arguments, composeIdentifierName, composeKvArguments, composeQueueArguments, composeR2Arguments, composeResourceName, validateEnvironment };