@develit-io/backend-sdk 5.15.1 → 5.15.2

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 CHANGED
@@ -3,6 +3,9 @@
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 commentJson = require('comment-json');
7
+ const node_fs = require('node:fs');
8
+ const path = require('@std/path');
6
9
  const text = require('@std/text');
7
10
  require('http-status-codes');
8
11
  const z = require('zod/v4/core');
@@ -10,8 +13,7 @@ const h3 = require('h3');
10
13
  const consola = require('consola');
11
14
  const fs = require('fs');
12
15
  const crypto$1 = require('node:crypto');
13
- const path = require('path');
14
- const commentJson = require('comment-json');
16
+ const path$1 = require('path');
15
17
  const superjson = require('superjson');
16
18
 
17
19
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
@@ -31,7 +33,7 @@ function _interopNamespaceCompat(e) {
31
33
  const z__namespace = /*#__PURE__*/_interopNamespaceCompat(z);
32
34
  const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
33
35
  const crypto__default = /*#__PURE__*/_interopDefaultCompat(crypto$1);
34
- const path__default = /*#__PURE__*/_interopDefaultCompat(path);
36
+ const path__default = /*#__PURE__*/_interopDefaultCompat(path$1);
35
37
  const superjson__default = /*#__PURE__*/_interopDefaultCompat(superjson);
36
38
 
37
39
  const base = {
@@ -52,8 +54,6 @@ const basePostgres = {
52
54
  }).default(drizzleOrm.sql`null`)
53
55
  };
54
56
 
55
- const ENVIRONMENT = ["dev", "test", "staging", "production"];
56
-
57
57
  const composeD1Arguments = ({
58
58
  resourceName
59
59
  }) => {
@@ -113,6 +113,11 @@ const composeR2Arguments = ({
113
113
  };
114
114
  };
115
115
 
116
+ async function loadWorkerConfig({ path: path$1 }) {
117
+ const workerConfigFile = node_fs.readFileSync(path.join(path$1, "./wrangler.jsonc"), "utf-8");
118
+ return commentJson.parse(workerConfigFile);
119
+ }
120
+
116
121
  const composeBindingName = ({
117
122
  resource,
118
123
  resourceName,
@@ -121,13 +126,14 @@ const composeBindingName = ({
121
126
  const convertedBindingName = bindingName ? text.toSnakeCase(bindingName) : `${text.toSnakeCase(resourceName)}_${resource}`;
122
127
  return convertedBindingName.toUpperCase();
123
128
  };
124
-
125
- const validateEnvironment = (environment) => {
126
- if (ENVIRONMENT.includes(environment)) {
127
- return environment;
128
- }
129
- return Number(environment);
129
+ const composeResourceName = ({
130
+ project,
131
+ environment,
132
+ resourceName
133
+ }) => {
134
+ return `${project}-${resourceName}-${environment}`;
130
135
  };
136
+
131
137
  class Infrastructure {
132
138
  project;
133
139
  environment;
@@ -141,85 +147,6 @@ class Infrastructure {
141
147
  this.environment = environment;
142
148
  this.sst = sst;
143
149
  }
144
- // TODO(Pookensivee): Make tests for this util
145
- composeResourceName({ resourceName }) {
146
- return `${this.project}-${resourceName}-${this.environment}`;
147
- }
148
- // TODO: Solve the circular dependency on post infrastructure deploy script
149
- // TODO: Cannot assign a queue as a producer, work around: https://developers.cloudflare.com/workers/wrangler/commands/#queues-consumer-add-script-name
150
- // async composeWorkerArguments({
151
- // resourceName,
152
- // path,
153
- // bindings = [],
154
- // }: {
155
- // resourceName: string
156
- // path: string
157
- // bindings?: Input<Kv | D1 | Queue | Worker | Bucket>[]
158
- // }) {
159
- // const workerConfig = this.loadWorkerConfig({ path })
160
- // const environmentVariables = this.extractEnvironmentVariables({ workerConfigEnv:
161
- // workerConfig.env as WorkerConfigEnv
162
- // })
163
- // // TODO: Fix this
164
- // if (
165
- // 'SERVICE_CONFIG' in environmentVariables &&
166
- // typeof environmentVariables.SERVICE_CONFIG === 'object'
167
- // ) {
168
- // environmentVariables.SERVICE_CONFIG = JSON.stringify(environmentVariables.SERVICE_CONFIG)
169
- // }
170
- // // TODO: Fix this
171
- // if (
172
- // 'EMAIL_SENDER' in environmentVariables &&
173
- // typeof environmentVariables.EMAIL_SENDER === 'object'
174
- // ) {
175
- // environmentVariables.EMAIL_SENDER = JSON.stringify(environmentVariables.EMAIL_SENDER)
176
- // }
177
- // return {
178
- // handler: join(path, './src/index.ts'),
179
- // environment: Object.entries(environmentVariables).reduce((acc, [key, value]) => ({
180
- // ...acc,
181
- // [key]: String(value)
182
- // }), {} as Record<string, string>),
183
- // link: bindings,
184
- // transform: {
185
- // worker: {
186
- // scriptName: this.composeResourceName({ resourceName }),
187
- // compatibilityDate: '2025-06-04',
188
- // compatibilityFlags: ['nodejs_compat'],
189
- // observability: {
190
- // enabled: true,
191
- // headSamplingRate: 1,
192
- // logs: {
193
- // // Check whether this disables logs completely or just invocation ones
194
- // enabled: false,
195
- // invocationLogs: false,
196
- // },
197
- // },
198
- // },
199
- // }
200
- // } satisfies Partial<WorkerArgs>
201
- // }
202
- // loadWorkerConfig({ path }: { path: string }) {
203
- // const workerConfigFile = readFileSync(
204
- // join(path, './wrangler.jsonc'),
205
- // 'utf-8',
206
- // )
207
- // TODO: Use parse from comment-json
208
- // const jsonString = workerConfigFile
209
- // .replace(/\/\*[\s\S]*?\*\//g, '')
210
- // .replace(/\/\/.*$/gm, '')
211
- // return JSON.parse(jsonString)
212
- // }
213
- // extractEnvironmentVariables({
214
- // workerConfigEnv,
215
- // }: {
216
- // workerConfigEnv: WorkerConfigEnv
217
- // }) {
218
- // if (typeof this.environment === 'number') {
219
- // return { ...workerConfigEnv.dev.vars, ENVIRONMENT: this.environment }
220
- // }
221
- // return { ...workerConfigEnv[this.environment].vars }
222
- // }
223
150
  /**
224
151
  * Creates an instance of Cloudflare KV.
225
152
  */
@@ -228,7 +155,11 @@ class Infrastructure {
228
155
  return new this.sst.cloudflare.Kv(
229
156
  `${composeBindingName({ resource: "kv", resourceName, bindingName })}`,
230
157
  composeKvArguments({
231
- resourceName: this.composeResourceName({ resourceName })
158
+ resourceName: composeResourceName({
159
+ project: this.project,
160
+ environment: this.environment,
161
+ resourceName
162
+ })
232
163
  })
233
164
  );
234
165
  }
@@ -240,7 +171,11 @@ class Infrastructure {
240
171
  return new this.sst.cloudflare.D1(
241
172
  `${composeBindingName({ resource: "d1", resourceName, bindingName })}`,
242
173
  composeD1Arguments({
243
- resourceName: this.composeResourceName({ resourceName })
174
+ resourceName: composeResourceName({
175
+ project: this.project,
176
+ environment: this.environment,
177
+ resourceName
178
+ })
244
179
  })
245
180
  );
246
181
  }
@@ -252,7 +187,11 @@ class Infrastructure {
252
187
  return new this.sst.cloudflare.Queue(
253
188
  `${composeBindingName({ resource: "queue", resourceName, bindingName })}`,
254
189
  composeQueueArguments({
255
- resourceName: this.composeResourceName({ resourceName }),
190
+ resourceName: composeResourceName({
191
+ project: this.project,
192
+ environment: this.environment,
193
+ resourceName
194
+ }),
256
195
  deliveryDelay,
257
196
  messageRetentionPeriod
258
197
  })
@@ -266,75 +205,26 @@ class Infrastructure {
266
205
  return new this.sst.cloudflare.Bucket(
267
206
  `${composeBindingName({ resource: "r2", resourceName, bindingName })}`,
268
207
  composeR2Arguments({
269
- resourceName: this.composeResourceName({ resourceName }),
208
+ resourceName: composeResourceName({
209
+ project: this.project,
210
+ environment: this.environment,
211
+ resourceName
212
+ }),
270
213
  storageClass
271
214
  })
272
215
  );
273
216
  }
274
- // TODO: Solve the circular dependency on post infrastructure deploy script
275
- // async worker({
276
- // resourceName,
277
- // bindingName,
278
- // path,
279
- // bindings = [],
280
- // }: {
281
- // resourceName: string
282
- // bindingName: string
283
- // path: string
284
- // bindings?: Input<Kv | D1 | Queue | Worker | Bucket>[]
285
- // }) {
286
- // return new sst.cloudflare.Worker(
287
- // this.composeBindingName({
288
- // resource: 'worker',
289
- // bindingName,
290
- // resourceName,
291
- // }),
292
- // await this.composeWorkerArguments({
293
- // resourceName: this.composeResourceName({ resourceName }),
294
- // path,
295
- // bindings,
296
- // }),
297
- // )
298
- // }
299
- // async service({
300
- // resourceName,
301
- // bindingName,
302
- // path,
303
- // bindings = [],
304
- // }: {
305
- // resourceName: string
306
- // bindingName?: string
307
- // path?: string
308
- // bindings?: Input<Kv | D1 | Queue | Worker | Bucket>[]
309
- // }) {
310
- // return this.worker({
311
- // resourceName: `${this.project}-${resourceName}-service-${this.environment}`,
312
- // bindingName: this.composeBindingName({
313
- // resource: 'service',
314
- // bindingName,
315
- // resourceName,
316
- // }),
317
- // path: `${path ?? `./services/${resourceName}`}`,
318
- // bindings,
319
- // })
320
- // }
321
- // // TODO: Add name
322
- // async orchestrator({
323
- // path,
324
- // bindings = [],
325
- // }: {
326
- // path?: string
327
- // bindings?: Input<Kv | D1 | Queue | Worker | Bucket>[]
328
- // }) {
329
- // return this.worker({
330
- // resourceName: `${this.project}-gateway-${this.environment}`,
331
- // bindingName: 'GATEWAY',
332
- // path: `${path ?? `./apps/gateway`}`,
333
- // bindings,
334
- // })
335
- // }
336
217
  }
337
218
 
219
+ const ENVIRONMENT = ["dev", "test", "staging", "production"];
220
+
221
+ const validateEnvironment = (environment) => {
222
+ if (ENVIRONMENT.includes(environment)) {
223
+ return environment;
224
+ }
225
+ return Number(environment);
226
+ };
227
+
338
228
  const ibanZodSchema = new z__namespace.$ZodString({
339
229
  type: "string",
340
230
  checks: [
@@ -991,6 +881,7 @@ exports.handleAction = handleAction;
991
881
  exports.handleActionResponse = handleActionResponse;
992
882
  exports.ibanZodSchema = ibanZodSchema;
993
883
  exports.isInternalError = isInternalError;
884
+ exports.loadWorkerConfig = loadWorkerConfig;
994
885
  exports.paginationQuerySchema = paginationQuerySchema;
995
886
  exports.paginationSchema = paginationSchema;
996
887
  exports.service = service;
package/dist/index.d.cts CHANGED
@@ -4,6 +4,7 @@ import * as drizzle_orm from 'drizzle-orm';
4
4
  import { ExtractTablesWithRelations, DBQueryConfig, BuildQueryResult } from 'drizzle-orm';
5
5
  import * as drizzle_orm_sqlite_core from 'drizzle-orm/sqlite-core';
6
6
  import { AnySQLiteTable } from 'drizzle-orm/sqlite-core';
7
+ import * as comment_json from 'comment-json';
7
8
  import { StatusCodes, ReasonPhrases } from 'http-status-codes';
8
9
  export { ReasonPhrases as InternalResponsePhrase, StatusCodes as InternalResponseStatus } from 'http-status-codes';
9
10
  import * as z from 'zod/v4/core';
@@ -28,7 +29,6 @@ type Project = 'creditio' | 'fp' | 'mdm' | 'moneio' | 'txs';
28
29
 
29
30
  type Environment = number | 'dev' | 'test' | 'staging' | 'production';
30
31
 
31
- declare const validateEnvironment: (environment: string) => Environment;
32
32
  interface SstInstance {
33
33
  cloudflare: {
34
34
  [key: string]: any;
@@ -43,9 +43,6 @@ declare class Infrastructure {
43
43
  environment: Environment;
44
44
  sst: SstInstance;
45
45
  });
46
- composeResourceName({ resourceName }: {
47
- resourceName: string;
48
- }): string;
49
46
  /**
50
47
  * Creates an instance of Cloudflare KV.
51
48
  */
@@ -112,15 +109,11 @@ declare class Infrastructure {
112
109
  }): any;
113
110
  }
114
111
 
115
- type Resource = 'kv' | 'd1' | 'queue' | 'r2' | 'worker' | 'service' | 'orchestrator';
112
+ declare function loadWorkerConfig({ path }: {
113
+ path: string;
114
+ }): Promise<comment_json.CommentJSONValue>;
116
115
 
117
- declare const composeBindingName: ({ resource, resourceName, bindingName, }: {
118
- resource: Resource;
119
- resourceName: string;
120
- bindingName?: string;
121
- }) => string;
122
-
123
- declare const ENVIRONMENT: string[];
116
+ type Resource = 'kv' | 'd1' | 'queue' | 'r2' | 'worker' | 'service' | 'orchestrator';
124
117
 
125
118
  type InternalErrorResponseStatus = Exclude<StatusCodes, 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207>;
126
119
  interface InternalError {
@@ -184,6 +177,16 @@ declare const paginationSchema: z.$ZodObject<Readonly<Readonly<{
184
177
  [k: string]: z.$ZodType<unknown, unknown, z.$ZodTypeInternals<unknown, unknown>>;
185
178
  }>>, z.$ZodObjectConfig>;
186
179
 
180
+ declare const composeBindingName: ({ resource, resourceName, bindingName, }: {
181
+ resource: Resource;
182
+ resourceName: string;
183
+ bindingName?: string;
184
+ }) => string;
185
+
186
+ declare const validateEnvironment: (environment: string) => Environment;
187
+
188
+ declare const ENVIRONMENT: string[];
189
+
187
190
  declare const handleActionResponse: <T>({ error, status, message, data, }: {
188
191
  error: boolean;
189
192
  status: number;
@@ -504,5 +507,5 @@ interface WithRetryCounterOptions {
504
507
  type AsyncMethod<TArgs extends unknown[] = unknown[], TResult = unknown> = (...args: TArgs) => Promise<TResult>;
505
508
  declare function cloudflareQueue<TArgs extends unknown[] = unknown[], TResult = unknown>(options: WithRetryCounterOptions): (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AsyncMethod<TArgs, TResult>>) => void;
506
509
 
507
- export { DatabaseTransaction, ENVIRONMENT, Infrastructure, RPCResponse, action, 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, useResult, useResultSync, uuidv4, validateEnvironment };
510
+ export { DatabaseTransaction, ENVIRONMENT, Infrastructure, RPCResponse, action, base, basePostgres, calculateExponentialBackoff, cloudflareQueue, composeBindingName, createAuditLogWriter, createInternalError, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getDrizzlePgConfig, getPgCredentials, getPgDatabaseIdFromWrangler, getPgLocalConnectionString, handleAction, handleActionResponse, ibanZodSchema, isInternalError, loadWorkerConfig, paginationQuerySchema, paginationSchema, service, swiftZodSchema, useResult, useResultSync, uuidv4, validateEnvironment };
508
511
  export type { ActionExecution, ActionHandlerOptions, AuditLogWriter, Command, CommandLogPayload, DevelitWorkerMethods, Environment, GatewayResponse, IRPCResponse, IncludeRelation, InferResultType, InternalError, InternalErrorResponseStatus, Project, ValidatedInput };
package/dist/index.d.mts CHANGED
@@ -4,6 +4,7 @@ import * as drizzle_orm from 'drizzle-orm';
4
4
  import { ExtractTablesWithRelations, DBQueryConfig, BuildQueryResult } from 'drizzle-orm';
5
5
  import * as drizzle_orm_sqlite_core from 'drizzle-orm/sqlite-core';
6
6
  import { AnySQLiteTable } from 'drizzle-orm/sqlite-core';
7
+ import * as comment_json from 'comment-json';
7
8
  import { StatusCodes, ReasonPhrases } from 'http-status-codes';
8
9
  export { ReasonPhrases as InternalResponsePhrase, StatusCodes as InternalResponseStatus } from 'http-status-codes';
9
10
  import * as z from 'zod/v4/core';
@@ -28,7 +29,6 @@ type Project = 'creditio' | 'fp' | 'mdm' | 'moneio' | 'txs';
28
29
 
29
30
  type Environment = number | 'dev' | 'test' | 'staging' | 'production';
30
31
 
31
- declare const validateEnvironment: (environment: string) => Environment;
32
32
  interface SstInstance {
33
33
  cloudflare: {
34
34
  [key: string]: any;
@@ -43,9 +43,6 @@ declare class Infrastructure {
43
43
  environment: Environment;
44
44
  sst: SstInstance;
45
45
  });
46
- composeResourceName({ resourceName }: {
47
- resourceName: string;
48
- }): string;
49
46
  /**
50
47
  * Creates an instance of Cloudflare KV.
51
48
  */
@@ -112,15 +109,11 @@ declare class Infrastructure {
112
109
  }): any;
113
110
  }
114
111
 
115
- type Resource = 'kv' | 'd1' | 'queue' | 'r2' | 'worker' | 'service' | 'orchestrator';
112
+ declare function loadWorkerConfig({ path }: {
113
+ path: string;
114
+ }): Promise<comment_json.CommentJSONValue>;
116
115
 
117
- declare const composeBindingName: ({ resource, resourceName, bindingName, }: {
118
- resource: Resource;
119
- resourceName: string;
120
- bindingName?: string;
121
- }) => string;
122
-
123
- declare const ENVIRONMENT: string[];
116
+ type Resource = 'kv' | 'd1' | 'queue' | 'r2' | 'worker' | 'service' | 'orchestrator';
124
117
 
125
118
  type InternalErrorResponseStatus = Exclude<StatusCodes, 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207>;
126
119
  interface InternalError {
@@ -184,6 +177,16 @@ declare const paginationSchema: z.$ZodObject<Readonly<Readonly<{
184
177
  [k: string]: z.$ZodType<unknown, unknown, z.$ZodTypeInternals<unknown, unknown>>;
185
178
  }>>, z.$ZodObjectConfig>;
186
179
 
180
+ declare const composeBindingName: ({ resource, resourceName, bindingName, }: {
181
+ resource: Resource;
182
+ resourceName: string;
183
+ bindingName?: string;
184
+ }) => string;
185
+
186
+ declare const validateEnvironment: (environment: string) => Environment;
187
+
188
+ declare const ENVIRONMENT: string[];
189
+
187
190
  declare const handleActionResponse: <T>({ error, status, message, data, }: {
188
191
  error: boolean;
189
192
  status: number;
@@ -504,5 +507,5 @@ interface WithRetryCounterOptions {
504
507
  type AsyncMethod<TArgs extends unknown[] = unknown[], TResult = unknown> = (...args: TArgs) => Promise<TResult>;
505
508
  declare function cloudflareQueue<TArgs extends unknown[] = unknown[], TResult = unknown>(options: WithRetryCounterOptions): (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AsyncMethod<TArgs, TResult>>) => void;
506
509
 
507
- export { DatabaseTransaction, ENVIRONMENT, Infrastructure, RPCResponse, action, 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, useResult, useResultSync, uuidv4, validateEnvironment };
510
+ export { DatabaseTransaction, ENVIRONMENT, Infrastructure, RPCResponse, action, base, basePostgres, calculateExponentialBackoff, cloudflareQueue, composeBindingName, createAuditLogWriter, createInternalError, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getDrizzlePgConfig, getPgCredentials, getPgDatabaseIdFromWrangler, getPgLocalConnectionString, handleAction, handleActionResponse, ibanZodSchema, isInternalError, loadWorkerConfig, paginationQuerySchema, paginationSchema, service, swiftZodSchema, useResult, useResultSync, uuidv4, validateEnvironment };
508
511
  export type { ActionExecution, ActionHandlerOptions, AuditLogWriter, Command, CommandLogPayload, DevelitWorkerMethods, Environment, GatewayResponse, IRPCResponse, IncludeRelation, InferResultType, InternalError, InternalErrorResponseStatus, Project, ValidatedInput };
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ import * as drizzle_orm from 'drizzle-orm';
4
4
  import { ExtractTablesWithRelations, DBQueryConfig, BuildQueryResult } from 'drizzle-orm';
5
5
  import * as drizzle_orm_sqlite_core from 'drizzle-orm/sqlite-core';
6
6
  import { AnySQLiteTable } from 'drizzle-orm/sqlite-core';
7
+ import * as comment_json from 'comment-json';
7
8
  import { StatusCodes, ReasonPhrases } from 'http-status-codes';
8
9
  export { ReasonPhrases as InternalResponsePhrase, StatusCodes as InternalResponseStatus } from 'http-status-codes';
9
10
  import * as z from 'zod/v4/core';
@@ -28,7 +29,6 @@ type Project = 'creditio' | 'fp' | 'mdm' | 'moneio' | 'txs';
28
29
 
29
30
  type Environment = number | 'dev' | 'test' | 'staging' | 'production';
30
31
 
31
- declare const validateEnvironment: (environment: string) => Environment;
32
32
  interface SstInstance {
33
33
  cloudflare: {
34
34
  [key: string]: any;
@@ -43,9 +43,6 @@ declare class Infrastructure {
43
43
  environment: Environment;
44
44
  sst: SstInstance;
45
45
  });
46
- composeResourceName({ resourceName }: {
47
- resourceName: string;
48
- }): string;
49
46
  /**
50
47
  * Creates an instance of Cloudflare KV.
51
48
  */
@@ -112,15 +109,11 @@ declare class Infrastructure {
112
109
  }): any;
113
110
  }
114
111
 
115
- type Resource = 'kv' | 'd1' | 'queue' | 'r2' | 'worker' | 'service' | 'orchestrator';
112
+ declare function loadWorkerConfig({ path }: {
113
+ path: string;
114
+ }): Promise<comment_json.CommentJSONValue>;
116
115
 
117
- declare const composeBindingName: ({ resource, resourceName, bindingName, }: {
118
- resource: Resource;
119
- resourceName: string;
120
- bindingName?: string;
121
- }) => string;
122
-
123
- declare const ENVIRONMENT: string[];
116
+ type Resource = 'kv' | 'd1' | 'queue' | 'r2' | 'worker' | 'service' | 'orchestrator';
124
117
 
125
118
  type InternalErrorResponseStatus = Exclude<StatusCodes, 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207>;
126
119
  interface InternalError {
@@ -184,6 +177,16 @@ declare const paginationSchema: z.$ZodObject<Readonly<Readonly<{
184
177
  [k: string]: z.$ZodType<unknown, unknown, z.$ZodTypeInternals<unknown, unknown>>;
185
178
  }>>, z.$ZodObjectConfig>;
186
179
 
180
+ declare const composeBindingName: ({ resource, resourceName, bindingName, }: {
181
+ resource: Resource;
182
+ resourceName: string;
183
+ bindingName?: string;
184
+ }) => string;
185
+
186
+ declare const validateEnvironment: (environment: string) => Environment;
187
+
188
+ declare const ENVIRONMENT: string[];
189
+
187
190
  declare const handleActionResponse: <T>({ error, status, message, data, }: {
188
191
  error: boolean;
189
192
  status: number;
@@ -504,5 +507,5 @@ interface WithRetryCounterOptions {
504
507
  type AsyncMethod<TArgs extends unknown[] = unknown[], TResult = unknown> = (...args: TArgs) => Promise<TResult>;
505
508
  declare function cloudflareQueue<TArgs extends unknown[] = unknown[], TResult = unknown>(options: WithRetryCounterOptions): (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AsyncMethod<TArgs, TResult>>) => void;
506
509
 
507
- export { DatabaseTransaction, ENVIRONMENT, Infrastructure, RPCResponse, action, 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, useResult, useResultSync, uuidv4, validateEnvironment };
510
+ export { DatabaseTransaction, ENVIRONMENT, Infrastructure, RPCResponse, action, base, basePostgres, calculateExponentialBackoff, cloudflareQueue, composeBindingName, createAuditLogWriter, createInternalError, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getDrizzlePgConfig, getPgCredentials, getPgDatabaseIdFromWrangler, getPgLocalConnectionString, handleAction, handleActionResponse, ibanZodSchema, isInternalError, loadWorkerConfig, paginationQuerySchema, paginationSchema, service, swiftZodSchema, useResult, useResultSync, uuidv4, validateEnvironment };
508
511
  export type { ActionExecution, ActionHandlerOptions, AuditLogWriter, Command, CommandLogPayload, DevelitWorkerMethods, Environment, GatewayResponse, IRPCResponse, IncludeRelation, InferResultType, InternalError, InternalErrorResponseStatus, Project, ValidatedInput };
package/dist/index.mjs CHANGED
@@ -1,6 +1,9 @@
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 { parse } from 'comment-json';
5
+ import { readFileSync } from 'node:fs';
6
+ import { join } from '@std/path';
4
7
  import { toSnakeCase } from '@std/text';
5
8
  import 'http-status-codes';
6
9
  import * as z from 'zod/v4/core';
@@ -9,7 +12,6 @@ import { consola } from 'consola';
9
12
  import fs from 'fs';
10
13
  import crypto$1 from 'node:crypto';
11
14
  import path from 'path';
12
- import { parse } from 'comment-json';
13
15
  import superjson from 'superjson';
14
16
 
15
17
  const base = {
@@ -30,8 +32,6 @@ const basePostgres = {
30
32
  }).default(sql`null`)
31
33
  };
32
34
 
33
- const ENVIRONMENT = ["dev", "test", "staging", "production"];
34
-
35
35
  const composeD1Arguments = ({
36
36
  resourceName
37
37
  }) => {
@@ -91,6 +91,11 @@ const composeR2Arguments = ({
91
91
  };
92
92
  };
93
93
 
94
+ async function loadWorkerConfig({ path }) {
95
+ const workerConfigFile = readFileSync(join(path, "./wrangler.jsonc"), "utf-8");
96
+ return parse(workerConfigFile);
97
+ }
98
+
94
99
  const composeBindingName = ({
95
100
  resource,
96
101
  resourceName,
@@ -99,13 +104,14 @@ const composeBindingName = ({
99
104
  const convertedBindingName = bindingName ? toSnakeCase(bindingName) : `${toSnakeCase(resourceName)}_${resource}`;
100
105
  return convertedBindingName.toUpperCase();
101
106
  };
102
-
103
- const validateEnvironment = (environment) => {
104
- if (ENVIRONMENT.includes(environment)) {
105
- return environment;
106
- }
107
- return Number(environment);
107
+ const composeResourceName = ({
108
+ project,
109
+ environment,
110
+ resourceName
111
+ }) => {
112
+ return `${project}-${resourceName}-${environment}`;
108
113
  };
114
+
109
115
  class Infrastructure {
110
116
  project;
111
117
  environment;
@@ -119,85 +125,6 @@ class Infrastructure {
119
125
  this.environment = environment;
120
126
  this.sst = sst;
121
127
  }
122
- // TODO(Pookensivee): Make tests for this util
123
- composeResourceName({ resourceName }) {
124
- return `${this.project}-${resourceName}-${this.environment}`;
125
- }
126
- // TODO: Solve the circular dependency on post infrastructure deploy script
127
- // TODO: Cannot assign a queue as a producer, work around: https://developers.cloudflare.com/workers/wrangler/commands/#queues-consumer-add-script-name
128
- // async composeWorkerArguments({
129
- // resourceName,
130
- // path,
131
- // bindings = [],
132
- // }: {
133
- // resourceName: string
134
- // path: string
135
- // bindings?: Input<Kv | D1 | Queue | Worker | Bucket>[]
136
- // }) {
137
- // const workerConfig = this.loadWorkerConfig({ path })
138
- // const environmentVariables = this.extractEnvironmentVariables({ workerConfigEnv:
139
- // workerConfig.env as WorkerConfigEnv
140
- // })
141
- // // TODO: Fix this
142
- // if (
143
- // 'SERVICE_CONFIG' in environmentVariables &&
144
- // typeof environmentVariables.SERVICE_CONFIG === 'object'
145
- // ) {
146
- // environmentVariables.SERVICE_CONFIG = JSON.stringify(environmentVariables.SERVICE_CONFIG)
147
- // }
148
- // // TODO: Fix this
149
- // if (
150
- // 'EMAIL_SENDER' in environmentVariables &&
151
- // typeof environmentVariables.EMAIL_SENDER === 'object'
152
- // ) {
153
- // environmentVariables.EMAIL_SENDER = JSON.stringify(environmentVariables.EMAIL_SENDER)
154
- // }
155
- // return {
156
- // handler: join(path, './src/index.ts'),
157
- // environment: Object.entries(environmentVariables).reduce((acc, [key, value]) => ({
158
- // ...acc,
159
- // [key]: String(value)
160
- // }), {} as Record<string, string>),
161
- // link: bindings,
162
- // transform: {
163
- // worker: {
164
- // scriptName: this.composeResourceName({ resourceName }),
165
- // compatibilityDate: '2025-06-04',
166
- // compatibilityFlags: ['nodejs_compat'],
167
- // observability: {
168
- // enabled: true,
169
- // headSamplingRate: 1,
170
- // logs: {
171
- // // Check whether this disables logs completely or just invocation ones
172
- // enabled: false,
173
- // invocationLogs: false,
174
- // },
175
- // },
176
- // },
177
- // }
178
- // } satisfies Partial<WorkerArgs>
179
- // }
180
- // loadWorkerConfig({ path }: { path: string }) {
181
- // const workerConfigFile = readFileSync(
182
- // join(path, './wrangler.jsonc'),
183
- // 'utf-8',
184
- // )
185
- // TODO: Use parse from comment-json
186
- // const jsonString = workerConfigFile
187
- // .replace(/\/\*[\s\S]*?\*\//g, '')
188
- // .replace(/\/\/.*$/gm, '')
189
- // return JSON.parse(jsonString)
190
- // }
191
- // extractEnvironmentVariables({
192
- // workerConfigEnv,
193
- // }: {
194
- // workerConfigEnv: WorkerConfigEnv
195
- // }) {
196
- // if (typeof this.environment === 'number') {
197
- // return { ...workerConfigEnv.dev.vars, ENVIRONMENT: this.environment }
198
- // }
199
- // return { ...workerConfigEnv[this.environment].vars }
200
- // }
201
128
  /**
202
129
  * Creates an instance of Cloudflare KV.
203
130
  */
@@ -206,7 +133,11 @@ class Infrastructure {
206
133
  return new this.sst.cloudflare.Kv(
207
134
  `${composeBindingName({ resource: "kv", resourceName, bindingName })}`,
208
135
  composeKvArguments({
209
- resourceName: this.composeResourceName({ resourceName })
136
+ resourceName: composeResourceName({
137
+ project: this.project,
138
+ environment: this.environment,
139
+ resourceName
140
+ })
210
141
  })
211
142
  );
212
143
  }
@@ -218,7 +149,11 @@ class Infrastructure {
218
149
  return new this.sst.cloudflare.D1(
219
150
  `${composeBindingName({ resource: "d1", resourceName, bindingName })}`,
220
151
  composeD1Arguments({
221
- resourceName: this.composeResourceName({ resourceName })
152
+ resourceName: composeResourceName({
153
+ project: this.project,
154
+ environment: this.environment,
155
+ resourceName
156
+ })
222
157
  })
223
158
  );
224
159
  }
@@ -230,7 +165,11 @@ class Infrastructure {
230
165
  return new this.sst.cloudflare.Queue(
231
166
  `${composeBindingName({ resource: "queue", resourceName, bindingName })}`,
232
167
  composeQueueArguments({
233
- resourceName: this.composeResourceName({ resourceName }),
168
+ resourceName: composeResourceName({
169
+ project: this.project,
170
+ environment: this.environment,
171
+ resourceName
172
+ }),
234
173
  deliveryDelay,
235
174
  messageRetentionPeriod
236
175
  })
@@ -244,75 +183,26 @@ class Infrastructure {
244
183
  return new this.sst.cloudflare.Bucket(
245
184
  `${composeBindingName({ resource: "r2", resourceName, bindingName })}`,
246
185
  composeR2Arguments({
247
- resourceName: this.composeResourceName({ resourceName }),
186
+ resourceName: composeResourceName({
187
+ project: this.project,
188
+ environment: this.environment,
189
+ resourceName
190
+ }),
248
191
  storageClass
249
192
  })
250
193
  );
251
194
  }
252
- // TODO: Solve the circular dependency on post infrastructure deploy script
253
- // async worker({
254
- // resourceName,
255
- // bindingName,
256
- // path,
257
- // bindings = [],
258
- // }: {
259
- // resourceName: string
260
- // bindingName: string
261
- // path: string
262
- // bindings?: Input<Kv | D1 | Queue | Worker | Bucket>[]
263
- // }) {
264
- // return new sst.cloudflare.Worker(
265
- // this.composeBindingName({
266
- // resource: 'worker',
267
- // bindingName,
268
- // resourceName,
269
- // }),
270
- // await this.composeWorkerArguments({
271
- // resourceName: this.composeResourceName({ resourceName }),
272
- // path,
273
- // bindings,
274
- // }),
275
- // )
276
- // }
277
- // async service({
278
- // resourceName,
279
- // bindingName,
280
- // path,
281
- // bindings = [],
282
- // }: {
283
- // resourceName: string
284
- // bindingName?: string
285
- // path?: string
286
- // bindings?: Input<Kv | D1 | Queue | Worker | Bucket>[]
287
- // }) {
288
- // return this.worker({
289
- // resourceName: `${this.project}-${resourceName}-service-${this.environment}`,
290
- // bindingName: this.composeBindingName({
291
- // resource: 'service',
292
- // bindingName,
293
- // resourceName,
294
- // }),
295
- // path: `${path ?? `./services/${resourceName}`}`,
296
- // bindings,
297
- // })
298
- // }
299
- // // TODO: Add name
300
- // async orchestrator({
301
- // path,
302
- // bindings = [],
303
- // }: {
304
- // path?: string
305
- // bindings?: Input<Kv | D1 | Queue | Worker | Bucket>[]
306
- // }) {
307
- // return this.worker({
308
- // resourceName: `${this.project}-gateway-${this.environment}`,
309
- // bindingName: 'GATEWAY',
310
- // path: `${path ?? `./apps/gateway`}`,
311
- // bindings,
312
- // })
313
- // }
314
195
  }
315
196
 
197
+ const ENVIRONMENT = ["dev", "test", "staging", "production"];
198
+
199
+ const validateEnvironment = (environment) => {
200
+ if (ENVIRONMENT.includes(environment)) {
201
+ return environment;
202
+ }
203
+ return Number(environment);
204
+ };
205
+
316
206
  const ibanZodSchema = new z.$ZodString({
317
207
  type: "string",
318
208
  checks: [
@@ -940,4 +830,4 @@ function develitWorker(Worker) {
940
830
  return DevelitWorker;
941
831
  }
942
832
 
943
- export { DatabaseTransaction, ENVIRONMENT, Infrastructure, RPCResponse, action, 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, useResult, useResultSync, uuidv4, validateEnvironment };
833
+ export { DatabaseTransaction, ENVIRONMENT, Infrastructure, RPCResponse, action, base, basePostgres, calculateExponentialBackoff, cloudflareQueue, composeBindingName, createAuditLogWriter, createInternalError, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getDrizzlePgConfig, getPgCredentials, getPgDatabaseIdFromWrangler, getPgLocalConnectionString, handleAction, handleActionResponse, ibanZodSchema, isInternalError, loadWorkerConfig, paginationQuerySchema, paginationSchema, service, swiftZodSchema, useResult, useResultSync, uuidv4, validateEnvironment };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@develit-io/backend-sdk",
3
- "version": "5.15.1",
3
+ "version": "5.15.2",
4
4
  "description": "Develit Backend SDK",
5
5
  "author": "Develit.io",
6
6
  "license": "ISC",