@develit-io/backend-sdk 5.8.3 → 5.9.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 +40 -19
- package/dist/index.d.cts +37 -5
- package/dist/index.d.mts +37 -5
- package/dist/index.d.ts +37 -5
- package/dist/index.mjs +38 -20
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -232,6 +232,22 @@ function createAuditLogWriter(table) {
|
|
|
232
232
|
};
|
|
233
233
|
}
|
|
234
234
|
|
|
235
|
+
function first(rows) {
|
|
236
|
+
return rows.length > 0 ? rows[0] : void 0;
|
|
237
|
+
}
|
|
238
|
+
function firstOrError(rows) {
|
|
239
|
+
if (rows.length === 0) {
|
|
240
|
+
throw new Error("Query did not return any data.");
|
|
241
|
+
}
|
|
242
|
+
return rows[0];
|
|
243
|
+
}
|
|
244
|
+
const uuidv4 = () => crypto.randomUUID();
|
|
245
|
+
const isRemoteEnvironment = () => {
|
|
246
|
+
const environment = process.env.ENVIRONMENT;
|
|
247
|
+
return environment && environment !== "localhost";
|
|
248
|
+
};
|
|
249
|
+
const getPostgresLocalConnectionString = () => `postgres://db_user:db_password@127.0.0.1:${process.env.DB_LOCAL_PORT}/db`;
|
|
250
|
+
|
|
235
251
|
function durableObjectNamespaceIdFromName(uniqueKey, name) {
|
|
236
252
|
const key = crypto__default.createHash("sha256").update(uniqueKey).digest();
|
|
237
253
|
const nameHmac = crypto__default.createHmac("sha256", key).update(name).digest().subarray(0, 16);
|
|
@@ -267,10 +283,6 @@ const getDatabaseIdFromWrangler = () => {
|
|
|
267
283
|
);
|
|
268
284
|
}
|
|
269
285
|
};
|
|
270
|
-
const isRemoteEnvironment = () => {
|
|
271
|
-
const environment = process.env.ENVIRONMENT;
|
|
272
|
-
return environment && environment !== "localhost";
|
|
273
|
-
};
|
|
274
286
|
const getLocalD1 = (databaseId) => {
|
|
275
287
|
const name = durableObjectNamespaceIdFromName(
|
|
276
288
|
"miniflare-D1DatabaseObject",
|
|
@@ -298,7 +310,11 @@ const getLocalD1 = (databaseId) => {
|
|
|
298
310
|
}
|
|
299
311
|
}
|
|
300
312
|
};
|
|
301
|
-
const
|
|
313
|
+
const getD1Credentials = () => {
|
|
314
|
+
const environment = process.env.ENVIRONMENT;
|
|
315
|
+
if (environment === "localhost") {
|
|
316
|
+
return {};
|
|
317
|
+
}
|
|
302
318
|
const databaseId = getDatabaseIdFromWrangler() ?? "";
|
|
303
319
|
if (isRemoteEnvironment()) {
|
|
304
320
|
return {
|
|
@@ -321,7 +337,7 @@ const drizzleD1Config = {
|
|
|
321
337
|
schema: "./src/database/schema/",
|
|
322
338
|
out: "./src/database/migrations/",
|
|
323
339
|
dialect: "sqlite",
|
|
324
|
-
...
|
|
340
|
+
...getD1Credentials()
|
|
325
341
|
};
|
|
326
342
|
|
|
327
343
|
class DatabaseTransaction {
|
|
@@ -386,24 +402,26 @@ const defineCommand = (handler) => {
|
|
|
386
402
|
});
|
|
387
403
|
};
|
|
388
404
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
405
|
+
const getPgCredentials = () => {
|
|
406
|
+
if (isRemoteEnvironment()) {
|
|
407
|
+
return {
|
|
408
|
+
dbCredentials: {
|
|
409
|
+
url: process.env.DATABASE_URL
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
} else {
|
|
413
|
+
return {
|
|
414
|
+
dbCredentials: {
|
|
415
|
+
url: getPostgresLocalConnectionString()
|
|
416
|
+
}
|
|
417
|
+
};
|
|
395
418
|
}
|
|
396
|
-
|
|
397
|
-
}
|
|
398
|
-
const uuidv4 = () => crypto.randomUUID();
|
|
399
|
-
|
|
419
|
+
};
|
|
400
420
|
const drizzlePgConfig = {
|
|
401
421
|
schema: "./src/database/schema/",
|
|
402
422
|
out: "./src/database/migrations/",
|
|
403
423
|
dialect: "postgresql",
|
|
404
|
-
|
|
405
|
-
url: process.env.DATABASE_URL
|
|
406
|
-
},
|
|
424
|
+
...getPgCredentials(),
|
|
407
425
|
migrations: {
|
|
408
426
|
table: "__drizzle_migrations",
|
|
409
427
|
schema: "public"
|
|
@@ -566,6 +584,9 @@ exports.drizzlePgConfig = drizzlePgConfig;
|
|
|
566
584
|
exports.durableObjectNamespaceIdFromName = durableObjectNamespaceIdFromName;
|
|
567
585
|
exports.first = first;
|
|
568
586
|
exports.firstOrError = firstOrError;
|
|
587
|
+
exports.getD1Credentials = getD1Credentials;
|
|
588
|
+
exports.getPgCredentials = getPgCredentials;
|
|
589
|
+
exports.getPostgresLocalConnectionString = getPostgresLocalConnectionString;
|
|
569
590
|
exports.handleAction = handleAction;
|
|
570
591
|
exports.handleActionResponse = handleActionResponse;
|
|
571
592
|
exports.ibanZodSchema = ibanZodSchema;
|
package/dist/index.d.cts
CHANGED
|
@@ -191,7 +191,33 @@ type AuditLogWriter<TAuditAction = string> = (logs: AuditLogPayload<TAuditAction
|
|
|
191
191
|
declare function createAuditLogWriter<TAuditAction = string>(table: AuditLogTable): AuditLogWriter<TAuditAction>;
|
|
192
192
|
|
|
193
193
|
declare function durableObjectNamespaceIdFromName(uniqueKey: string, name: string): string;
|
|
194
|
+
declare const getD1Credentials: () => {
|
|
195
|
+
driver?: undefined;
|
|
196
|
+
dbCredentials?: undefined;
|
|
197
|
+
} | {
|
|
198
|
+
driver: string;
|
|
199
|
+
dbCredentials: {
|
|
200
|
+
accountId: string | undefined;
|
|
201
|
+
databaseId: string;
|
|
202
|
+
token: string | undefined;
|
|
203
|
+
url?: undefined;
|
|
204
|
+
};
|
|
205
|
+
} | {
|
|
206
|
+
dbCredentials: {
|
|
207
|
+
url: string | undefined;
|
|
208
|
+
accountId?: undefined;
|
|
209
|
+
databaseId?: undefined;
|
|
210
|
+
token?: undefined;
|
|
211
|
+
};
|
|
212
|
+
driver?: undefined;
|
|
213
|
+
};
|
|
194
214
|
declare const drizzleD1Config: {
|
|
215
|
+
driver?: undefined;
|
|
216
|
+
dbCredentials?: undefined;
|
|
217
|
+
schema: string;
|
|
218
|
+
out: string;
|
|
219
|
+
dialect: "sqlite";
|
|
220
|
+
} | {
|
|
195
221
|
driver: string;
|
|
196
222
|
dbCredentials: {
|
|
197
223
|
accountId: string | undefined;
|
|
@@ -244,6 +270,7 @@ declare class DatabaseTransaction<TAuditAction = string> {
|
|
|
244
270
|
declare function first<T>(rows: T[]): T | undefined;
|
|
245
271
|
declare function firstOrError<T>(rows: T[]): T;
|
|
246
272
|
declare const uuidv4: () => `${string}-${string}-${string}-${string}-${string}`;
|
|
273
|
+
declare const getPostgresLocalConnectionString: () => string;
|
|
247
274
|
|
|
248
275
|
declare const createInternalError: (error: unknown, details?: {
|
|
249
276
|
status?: InternalErrorResponseStatus;
|
|
@@ -252,17 +279,22 @@ declare const createInternalError: (error: unknown, details?: {
|
|
|
252
279
|
}) => InternalError;
|
|
253
280
|
declare const isInternalError: (error: unknown) => error is InternalError;
|
|
254
281
|
|
|
255
|
-
declare const
|
|
256
|
-
schema: string;
|
|
257
|
-
out: string;
|
|
258
|
-
dialect: "postgresql";
|
|
282
|
+
declare const getPgCredentials: () => {
|
|
259
283
|
dbCredentials: {
|
|
260
284
|
url: string;
|
|
261
285
|
};
|
|
286
|
+
};
|
|
287
|
+
declare const drizzlePgConfig: {
|
|
262
288
|
migrations: {
|
|
263
289
|
table: string;
|
|
264
290
|
schema: string;
|
|
265
291
|
};
|
|
292
|
+
dbCredentials: {
|
|
293
|
+
url: string;
|
|
294
|
+
};
|
|
295
|
+
schema: string;
|
|
296
|
+
out: string;
|
|
297
|
+
dialect: "postgresql";
|
|
266
298
|
};
|
|
267
299
|
|
|
268
300
|
declare const calculateExponentialBackoff: (attempts: number, baseDelaySeconds: number) => number;
|
|
@@ -364,4 +396,4 @@ interface WithRetryCounterOptions {
|
|
|
364
396
|
type AsyncMethod<TArgs extends unknown[] = unknown[], TResult = unknown> = (...args: TArgs) => Promise<TResult>;
|
|
365
397
|
declare function cloudflareQueue<TArgs extends unknown[] = unknown[], TResult = unknown>(options: WithRetryCounterOptions): (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AsyncMethod<TArgs, TResult>>) => void;
|
|
366
398
|
|
|
367
|
-
export { type ActionExecution, type ActionHandlerOptions, type AuditLogWriter, type Command, type CommandLogPayload, DatabaseTransaction, type DevelitWorkerMethods, type GatewayResponse, type IRPCResponse, type IncludeRelation, type InferResultType, type InternalError, type InternalErrorResponseStatus, RPCResponse, type ValidatedInput, action, base, basePostgres, calculateExponentialBackoff, cloudflareQueue, createAuditLogWriter, createInternalError, defineCommand, develitWorker, drizzleD1Config, drizzlePgConfig, durableObjectNamespaceIdFromName, first, firstOrError, handleAction, handleActionResponse, ibanZodSchema, isInternalError, service, swiftZodSchema, useResult, useResultSync, uuidv4 };
|
|
399
|
+
export { type ActionExecution, type ActionHandlerOptions, type AuditLogWriter, type Command, type CommandLogPayload, DatabaseTransaction, type DevelitWorkerMethods, type GatewayResponse, type IRPCResponse, type IncludeRelation, type InferResultType, type InternalError, type InternalErrorResponseStatus, RPCResponse, type ValidatedInput, action, base, basePostgres, calculateExponentialBackoff, cloudflareQueue, createAuditLogWriter, createInternalError, defineCommand, develitWorker, drizzleD1Config, drizzlePgConfig, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getPgCredentials, getPostgresLocalConnectionString, handleAction, handleActionResponse, ibanZodSchema, isInternalError, service, swiftZodSchema, useResult, useResultSync, uuidv4 };
|
package/dist/index.d.mts
CHANGED
|
@@ -191,7 +191,33 @@ type AuditLogWriter<TAuditAction = string> = (logs: AuditLogPayload<TAuditAction
|
|
|
191
191
|
declare function createAuditLogWriter<TAuditAction = string>(table: AuditLogTable): AuditLogWriter<TAuditAction>;
|
|
192
192
|
|
|
193
193
|
declare function durableObjectNamespaceIdFromName(uniqueKey: string, name: string): string;
|
|
194
|
+
declare const getD1Credentials: () => {
|
|
195
|
+
driver?: undefined;
|
|
196
|
+
dbCredentials?: undefined;
|
|
197
|
+
} | {
|
|
198
|
+
driver: string;
|
|
199
|
+
dbCredentials: {
|
|
200
|
+
accountId: string | undefined;
|
|
201
|
+
databaseId: string;
|
|
202
|
+
token: string | undefined;
|
|
203
|
+
url?: undefined;
|
|
204
|
+
};
|
|
205
|
+
} | {
|
|
206
|
+
dbCredentials: {
|
|
207
|
+
url: string | undefined;
|
|
208
|
+
accountId?: undefined;
|
|
209
|
+
databaseId?: undefined;
|
|
210
|
+
token?: undefined;
|
|
211
|
+
};
|
|
212
|
+
driver?: undefined;
|
|
213
|
+
};
|
|
194
214
|
declare const drizzleD1Config: {
|
|
215
|
+
driver?: undefined;
|
|
216
|
+
dbCredentials?: undefined;
|
|
217
|
+
schema: string;
|
|
218
|
+
out: string;
|
|
219
|
+
dialect: "sqlite";
|
|
220
|
+
} | {
|
|
195
221
|
driver: string;
|
|
196
222
|
dbCredentials: {
|
|
197
223
|
accountId: string | undefined;
|
|
@@ -244,6 +270,7 @@ declare class DatabaseTransaction<TAuditAction = string> {
|
|
|
244
270
|
declare function first<T>(rows: T[]): T | undefined;
|
|
245
271
|
declare function firstOrError<T>(rows: T[]): T;
|
|
246
272
|
declare const uuidv4: () => `${string}-${string}-${string}-${string}-${string}`;
|
|
273
|
+
declare const getPostgresLocalConnectionString: () => string;
|
|
247
274
|
|
|
248
275
|
declare const createInternalError: (error: unknown, details?: {
|
|
249
276
|
status?: InternalErrorResponseStatus;
|
|
@@ -252,17 +279,22 @@ declare const createInternalError: (error: unknown, details?: {
|
|
|
252
279
|
}) => InternalError;
|
|
253
280
|
declare const isInternalError: (error: unknown) => error is InternalError;
|
|
254
281
|
|
|
255
|
-
declare const
|
|
256
|
-
schema: string;
|
|
257
|
-
out: string;
|
|
258
|
-
dialect: "postgresql";
|
|
282
|
+
declare const getPgCredentials: () => {
|
|
259
283
|
dbCredentials: {
|
|
260
284
|
url: string;
|
|
261
285
|
};
|
|
286
|
+
};
|
|
287
|
+
declare const drizzlePgConfig: {
|
|
262
288
|
migrations: {
|
|
263
289
|
table: string;
|
|
264
290
|
schema: string;
|
|
265
291
|
};
|
|
292
|
+
dbCredentials: {
|
|
293
|
+
url: string;
|
|
294
|
+
};
|
|
295
|
+
schema: string;
|
|
296
|
+
out: string;
|
|
297
|
+
dialect: "postgresql";
|
|
266
298
|
};
|
|
267
299
|
|
|
268
300
|
declare const calculateExponentialBackoff: (attempts: number, baseDelaySeconds: number) => number;
|
|
@@ -364,4 +396,4 @@ interface WithRetryCounterOptions {
|
|
|
364
396
|
type AsyncMethod<TArgs extends unknown[] = unknown[], TResult = unknown> = (...args: TArgs) => Promise<TResult>;
|
|
365
397
|
declare function cloudflareQueue<TArgs extends unknown[] = unknown[], TResult = unknown>(options: WithRetryCounterOptions): (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AsyncMethod<TArgs, TResult>>) => void;
|
|
366
398
|
|
|
367
|
-
export { type ActionExecution, type ActionHandlerOptions, type AuditLogWriter, type Command, type CommandLogPayload, DatabaseTransaction, type DevelitWorkerMethods, type GatewayResponse, type IRPCResponse, type IncludeRelation, type InferResultType, type InternalError, type InternalErrorResponseStatus, RPCResponse, type ValidatedInput, action, base, basePostgres, calculateExponentialBackoff, cloudflareQueue, createAuditLogWriter, createInternalError, defineCommand, develitWorker, drizzleD1Config, drizzlePgConfig, durableObjectNamespaceIdFromName, first, firstOrError, handleAction, handleActionResponse, ibanZodSchema, isInternalError, service, swiftZodSchema, useResult, useResultSync, uuidv4 };
|
|
399
|
+
export { type ActionExecution, type ActionHandlerOptions, type AuditLogWriter, type Command, type CommandLogPayload, DatabaseTransaction, type DevelitWorkerMethods, type GatewayResponse, type IRPCResponse, type IncludeRelation, type InferResultType, type InternalError, type InternalErrorResponseStatus, RPCResponse, type ValidatedInput, action, base, basePostgres, calculateExponentialBackoff, cloudflareQueue, createAuditLogWriter, createInternalError, defineCommand, develitWorker, drizzleD1Config, drizzlePgConfig, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getPgCredentials, getPostgresLocalConnectionString, handleAction, handleActionResponse, ibanZodSchema, isInternalError, service, swiftZodSchema, useResult, useResultSync, uuidv4 };
|
package/dist/index.d.ts
CHANGED
|
@@ -191,7 +191,33 @@ type AuditLogWriter<TAuditAction = string> = (logs: AuditLogPayload<TAuditAction
|
|
|
191
191
|
declare function createAuditLogWriter<TAuditAction = string>(table: AuditLogTable): AuditLogWriter<TAuditAction>;
|
|
192
192
|
|
|
193
193
|
declare function durableObjectNamespaceIdFromName(uniqueKey: string, name: string): string;
|
|
194
|
+
declare const getD1Credentials: () => {
|
|
195
|
+
driver?: undefined;
|
|
196
|
+
dbCredentials?: undefined;
|
|
197
|
+
} | {
|
|
198
|
+
driver: string;
|
|
199
|
+
dbCredentials: {
|
|
200
|
+
accountId: string | undefined;
|
|
201
|
+
databaseId: string;
|
|
202
|
+
token: string | undefined;
|
|
203
|
+
url?: undefined;
|
|
204
|
+
};
|
|
205
|
+
} | {
|
|
206
|
+
dbCredentials: {
|
|
207
|
+
url: string | undefined;
|
|
208
|
+
accountId?: undefined;
|
|
209
|
+
databaseId?: undefined;
|
|
210
|
+
token?: undefined;
|
|
211
|
+
};
|
|
212
|
+
driver?: undefined;
|
|
213
|
+
};
|
|
194
214
|
declare const drizzleD1Config: {
|
|
215
|
+
driver?: undefined;
|
|
216
|
+
dbCredentials?: undefined;
|
|
217
|
+
schema: string;
|
|
218
|
+
out: string;
|
|
219
|
+
dialect: "sqlite";
|
|
220
|
+
} | {
|
|
195
221
|
driver: string;
|
|
196
222
|
dbCredentials: {
|
|
197
223
|
accountId: string | undefined;
|
|
@@ -244,6 +270,7 @@ declare class DatabaseTransaction<TAuditAction = string> {
|
|
|
244
270
|
declare function first<T>(rows: T[]): T | undefined;
|
|
245
271
|
declare function firstOrError<T>(rows: T[]): T;
|
|
246
272
|
declare const uuidv4: () => `${string}-${string}-${string}-${string}-${string}`;
|
|
273
|
+
declare const getPostgresLocalConnectionString: () => string;
|
|
247
274
|
|
|
248
275
|
declare const createInternalError: (error: unknown, details?: {
|
|
249
276
|
status?: InternalErrorResponseStatus;
|
|
@@ -252,17 +279,22 @@ declare const createInternalError: (error: unknown, details?: {
|
|
|
252
279
|
}) => InternalError;
|
|
253
280
|
declare const isInternalError: (error: unknown) => error is InternalError;
|
|
254
281
|
|
|
255
|
-
declare const
|
|
256
|
-
schema: string;
|
|
257
|
-
out: string;
|
|
258
|
-
dialect: "postgresql";
|
|
282
|
+
declare const getPgCredentials: () => {
|
|
259
283
|
dbCredentials: {
|
|
260
284
|
url: string;
|
|
261
285
|
};
|
|
286
|
+
};
|
|
287
|
+
declare const drizzlePgConfig: {
|
|
262
288
|
migrations: {
|
|
263
289
|
table: string;
|
|
264
290
|
schema: string;
|
|
265
291
|
};
|
|
292
|
+
dbCredentials: {
|
|
293
|
+
url: string;
|
|
294
|
+
};
|
|
295
|
+
schema: string;
|
|
296
|
+
out: string;
|
|
297
|
+
dialect: "postgresql";
|
|
266
298
|
};
|
|
267
299
|
|
|
268
300
|
declare const calculateExponentialBackoff: (attempts: number, baseDelaySeconds: number) => number;
|
|
@@ -364,4 +396,4 @@ interface WithRetryCounterOptions {
|
|
|
364
396
|
type AsyncMethod<TArgs extends unknown[] = unknown[], TResult = unknown> = (...args: TArgs) => Promise<TResult>;
|
|
365
397
|
declare function cloudflareQueue<TArgs extends unknown[] = unknown[], TResult = unknown>(options: WithRetryCounterOptions): (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AsyncMethod<TArgs, TResult>>) => void;
|
|
366
398
|
|
|
367
|
-
export { type ActionExecution, type ActionHandlerOptions, type AuditLogWriter, type Command, type CommandLogPayload, DatabaseTransaction, type DevelitWorkerMethods, type GatewayResponse, type IRPCResponse, type IncludeRelation, type InferResultType, type InternalError, type InternalErrorResponseStatus, RPCResponse, type ValidatedInput, action, base, basePostgres, calculateExponentialBackoff, cloudflareQueue, createAuditLogWriter, createInternalError, defineCommand, develitWorker, drizzleD1Config, drizzlePgConfig, durableObjectNamespaceIdFromName, first, firstOrError, handleAction, handleActionResponse, ibanZodSchema, isInternalError, service, swiftZodSchema, useResult, useResultSync, uuidv4 };
|
|
399
|
+
export { type ActionExecution, type ActionHandlerOptions, type AuditLogWriter, type Command, type CommandLogPayload, DatabaseTransaction, type DevelitWorkerMethods, type GatewayResponse, type IRPCResponse, type IncludeRelation, type InferResultType, type InternalError, type InternalErrorResponseStatus, RPCResponse, type ValidatedInput, action, base, basePostgres, calculateExponentialBackoff, cloudflareQueue, createAuditLogWriter, createInternalError, defineCommand, develitWorker, drizzleD1Config, drizzlePgConfig, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getPgCredentials, getPostgresLocalConnectionString, handleAction, handleActionResponse, ibanZodSchema, isInternalError, service, swiftZodSchema, useResult, useResultSync, uuidv4 };
|
package/dist/index.mjs
CHANGED
|
@@ -210,6 +210,22 @@ function createAuditLogWriter(table) {
|
|
|
210
210
|
};
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
+
function first(rows) {
|
|
214
|
+
return rows.length > 0 ? rows[0] : void 0;
|
|
215
|
+
}
|
|
216
|
+
function firstOrError(rows) {
|
|
217
|
+
if (rows.length === 0) {
|
|
218
|
+
throw new Error("Query did not return any data.");
|
|
219
|
+
}
|
|
220
|
+
return rows[0];
|
|
221
|
+
}
|
|
222
|
+
const uuidv4 = () => crypto.randomUUID();
|
|
223
|
+
const isRemoteEnvironment = () => {
|
|
224
|
+
const environment = process.env.ENVIRONMENT;
|
|
225
|
+
return environment && environment !== "localhost";
|
|
226
|
+
};
|
|
227
|
+
const getPostgresLocalConnectionString = () => `postgres://db_user:db_password@127.0.0.1:${process.env.DB_LOCAL_PORT}/db`;
|
|
228
|
+
|
|
213
229
|
function durableObjectNamespaceIdFromName(uniqueKey, name) {
|
|
214
230
|
const key = crypto$1.createHash("sha256").update(uniqueKey).digest();
|
|
215
231
|
const nameHmac = crypto$1.createHmac("sha256", key).update(name).digest().subarray(0, 16);
|
|
@@ -245,10 +261,6 @@ const getDatabaseIdFromWrangler = () => {
|
|
|
245
261
|
);
|
|
246
262
|
}
|
|
247
263
|
};
|
|
248
|
-
const isRemoteEnvironment = () => {
|
|
249
|
-
const environment = process.env.ENVIRONMENT;
|
|
250
|
-
return environment && environment !== "localhost";
|
|
251
|
-
};
|
|
252
264
|
const getLocalD1 = (databaseId) => {
|
|
253
265
|
const name = durableObjectNamespaceIdFromName(
|
|
254
266
|
"miniflare-D1DatabaseObject",
|
|
@@ -276,7 +288,11 @@ const getLocalD1 = (databaseId) => {
|
|
|
276
288
|
}
|
|
277
289
|
}
|
|
278
290
|
};
|
|
279
|
-
const
|
|
291
|
+
const getD1Credentials = () => {
|
|
292
|
+
const environment = process.env.ENVIRONMENT;
|
|
293
|
+
if (environment === "localhost") {
|
|
294
|
+
return {};
|
|
295
|
+
}
|
|
280
296
|
const databaseId = getDatabaseIdFromWrangler() ?? "";
|
|
281
297
|
if (isRemoteEnvironment()) {
|
|
282
298
|
return {
|
|
@@ -299,7 +315,7 @@ const drizzleD1Config = {
|
|
|
299
315
|
schema: "./src/database/schema/",
|
|
300
316
|
out: "./src/database/migrations/",
|
|
301
317
|
dialect: "sqlite",
|
|
302
|
-
...
|
|
318
|
+
...getD1Credentials()
|
|
303
319
|
};
|
|
304
320
|
|
|
305
321
|
class DatabaseTransaction {
|
|
@@ -364,24 +380,26 @@ const defineCommand = (handler) => {
|
|
|
364
380
|
});
|
|
365
381
|
};
|
|
366
382
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
383
|
+
const getPgCredentials = () => {
|
|
384
|
+
if (isRemoteEnvironment()) {
|
|
385
|
+
return {
|
|
386
|
+
dbCredentials: {
|
|
387
|
+
url: process.env.DATABASE_URL
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
} else {
|
|
391
|
+
return {
|
|
392
|
+
dbCredentials: {
|
|
393
|
+
url: getPostgresLocalConnectionString()
|
|
394
|
+
}
|
|
395
|
+
};
|
|
373
396
|
}
|
|
374
|
-
|
|
375
|
-
}
|
|
376
|
-
const uuidv4 = () => crypto.randomUUID();
|
|
377
|
-
|
|
397
|
+
};
|
|
378
398
|
const drizzlePgConfig = {
|
|
379
399
|
schema: "./src/database/schema/",
|
|
380
400
|
out: "./src/database/migrations/",
|
|
381
401
|
dialect: "postgresql",
|
|
382
|
-
|
|
383
|
-
url: process.env.DATABASE_URL
|
|
384
|
-
},
|
|
402
|
+
...getPgCredentials(),
|
|
385
403
|
migrations: {
|
|
386
404
|
table: "__drizzle_migrations",
|
|
387
405
|
schema: "public"
|
|
@@ -528,4 +546,4 @@ function develitWorker(Worker) {
|
|
|
528
546
|
return DevelitWorker;
|
|
529
547
|
}
|
|
530
548
|
|
|
531
|
-
export { DatabaseTransaction, RPCResponse, action, base, basePostgres, calculateExponentialBackoff, cloudflareQueue, createAuditLogWriter, createInternalError, defineCommand, develitWorker, drizzleD1Config, drizzlePgConfig, durableObjectNamespaceIdFromName, first, firstOrError, handleAction, handleActionResponse, ibanZodSchema, isInternalError, service, swiftZodSchema, useResult, useResultSync, uuidv4 };
|
|
549
|
+
export { DatabaseTransaction, RPCResponse, action, base, basePostgres, calculateExponentialBackoff, cloudflareQueue, createAuditLogWriter, createInternalError, defineCommand, develitWorker, drizzleD1Config, drizzlePgConfig, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getPgCredentials, getPostgresLocalConnectionString, handleAction, handleActionResponse, ibanZodSchema, isInternalError, service, swiftZodSchema, useResult, useResultSync, uuidv4 };
|