@develit-io/backend-sdk 5.8.2 → 5.9.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.cjs CHANGED
@@ -10,7 +10,7 @@ const consola = require('consola');
10
10
  const fs = require('fs');
11
11
  const crypto$1 = require('node:crypto');
12
12
  const path = require('path');
13
- const main_js = require('jsonc-parser/lib/esm/main.js');
13
+ const commentJson = require('comment-json');
14
14
  const superjson = require('superjson');
15
15
 
16
16
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
@@ -232,6 +232,21 @@ 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
+
235
250
  function durableObjectNamespaceIdFromName(uniqueKey, name) {
236
251
  const key = crypto__default.createHash("sha256").update(uniqueKey).digest();
237
252
  const nameHmac = crypto__default.createHmac("sha256", key).update(name).digest().subarray(0, 16);
@@ -242,11 +257,7 @@ const getDatabaseIdFromWrangler = () => {
242
257
  try {
243
258
  const wranglerPath = path__default.resolve("./wrangler.jsonc");
244
259
  const wranglerContent = fs__default.readFileSync(wranglerPath, "utf-8");
245
- const errors = [];
246
- const config = main_js.parse(wranglerContent, errors, { allowTrailingComma: true });
247
- if (errors.length) {
248
- throw new Error("Invalid JSONC in wrangler.jsonc");
249
- }
260
+ const config = commentJson.parse(wranglerContent);
250
261
  const environment = process.env.ENVIRONMENT || "localhost";
251
262
  let databaseId;
252
263
  if (environment !== "localhost" && config.env?.[environment]) {
@@ -271,10 +282,6 @@ const getDatabaseIdFromWrangler = () => {
271
282
  );
272
283
  }
273
284
  };
274
- const isRemoteEnvironment = () => {
275
- const environment = process.env.ENVIRONMENT;
276
- return environment && environment !== "localhost";
277
- };
278
285
  const getLocalD1 = (databaseId) => {
279
286
  const name = durableObjectNamespaceIdFromName(
280
287
  "miniflare-D1DatabaseObject",
@@ -302,7 +309,11 @@ const getLocalD1 = (databaseId) => {
302
309
  }
303
310
  }
304
311
  };
305
- const getCredentials = () => {
312
+ const getD1Credentials = () => {
313
+ const environment = process.env.ENVIRONMENT;
314
+ if (environment === "localhost") {
315
+ return {};
316
+ }
306
317
  const databaseId = getDatabaseIdFromWrangler() ?? "";
307
318
  if (isRemoteEnvironment()) {
308
319
  return {
@@ -325,7 +336,7 @@ const drizzleD1Config = {
325
336
  schema: "./src/database/schema/",
326
337
  out: "./src/database/migrations/",
327
338
  dialect: "sqlite",
328
- ...getCredentials()
339
+ ...getD1Credentials()
329
340
  };
330
341
 
331
342
  class DatabaseTransaction {
@@ -390,24 +401,26 @@ const defineCommand = (handler) => {
390
401
  });
391
402
  };
392
403
 
393
- function first(rows) {
394
- return rows.length > 0 ? rows[0] : void 0;
395
- }
396
- function firstOrError(rows) {
397
- if (rows.length === 0) {
398
- throw new Error("Query did not return any data.");
404
+ const getPgCredentials = () => {
405
+ if (isRemoteEnvironment()) {
406
+ return {
407
+ dbCredentials: {
408
+ url: process.env.DATABASE_URL
409
+ }
410
+ };
411
+ } else {
412
+ return {
413
+ dbCredentials: {
414
+ url: `postgres://db_user:db_password@127.0.0.1:${process.env.DB_LOCAL_PORT}/db`
415
+ }
416
+ };
399
417
  }
400
- return rows[0];
401
- }
402
- const uuidv4 = () => crypto.randomUUID();
403
-
418
+ };
404
419
  const drizzlePgConfig = {
405
420
  schema: "./src/database/schema/",
406
421
  out: "./src/database/migrations/",
407
422
  dialect: "postgresql",
408
- dbCredentials: {
409
- url: process.env.DATABASE_URL
410
- },
423
+ ...getPgCredentials(),
411
424
  migrations: {
412
425
  table: "__drizzle_migrations",
413
426
  schema: "public"
package/dist/index.d.cts CHANGED
@@ -192,6 +192,12 @@ declare function createAuditLogWriter<TAuditAction = string>(table: AuditLogTabl
192
192
 
193
193
  declare function durableObjectNamespaceIdFromName(uniqueKey: string, name: string): string;
194
194
  declare const drizzleD1Config: {
195
+ driver?: undefined;
196
+ dbCredentials?: undefined;
197
+ schema: string;
198
+ out: string;
199
+ dialect: "sqlite";
200
+ } | {
195
201
  driver: string;
196
202
  dbCredentials: {
197
203
  accountId: string | undefined;
@@ -253,16 +259,16 @@ declare const createInternalError: (error: unknown, details?: {
253
259
  declare const isInternalError: (error: unknown) => error is InternalError;
254
260
 
255
261
  declare const drizzlePgConfig: {
256
- schema: string;
257
- out: string;
258
- dialect: "postgresql";
259
- dbCredentials: {
260
- url: string;
261
- };
262
262
  migrations: {
263
263
  table: string;
264
264
  schema: string;
265
265
  };
266
+ dbCredentials: {
267
+ url: string;
268
+ };
269
+ schema: string;
270
+ out: string;
271
+ dialect: "postgresql";
266
272
  };
267
273
 
268
274
  declare const calculateExponentialBackoff: (attempts: number, baseDelaySeconds: number) => number;
package/dist/index.d.mts CHANGED
@@ -192,6 +192,12 @@ declare function createAuditLogWriter<TAuditAction = string>(table: AuditLogTabl
192
192
 
193
193
  declare function durableObjectNamespaceIdFromName(uniqueKey: string, name: string): string;
194
194
  declare const drizzleD1Config: {
195
+ driver?: undefined;
196
+ dbCredentials?: undefined;
197
+ schema: string;
198
+ out: string;
199
+ dialect: "sqlite";
200
+ } | {
195
201
  driver: string;
196
202
  dbCredentials: {
197
203
  accountId: string | undefined;
@@ -253,16 +259,16 @@ declare const createInternalError: (error: unknown, details?: {
253
259
  declare const isInternalError: (error: unknown) => error is InternalError;
254
260
 
255
261
  declare const drizzlePgConfig: {
256
- schema: string;
257
- out: string;
258
- dialect: "postgresql";
259
- dbCredentials: {
260
- url: string;
261
- };
262
262
  migrations: {
263
263
  table: string;
264
264
  schema: string;
265
265
  };
266
+ dbCredentials: {
267
+ url: string;
268
+ };
269
+ schema: string;
270
+ out: string;
271
+ dialect: "postgresql";
266
272
  };
267
273
 
268
274
  declare const calculateExponentialBackoff: (attempts: number, baseDelaySeconds: number) => number;
package/dist/index.d.ts CHANGED
@@ -192,6 +192,12 @@ declare function createAuditLogWriter<TAuditAction = string>(table: AuditLogTabl
192
192
 
193
193
  declare function durableObjectNamespaceIdFromName(uniqueKey: string, name: string): string;
194
194
  declare const drizzleD1Config: {
195
+ driver?: undefined;
196
+ dbCredentials?: undefined;
197
+ schema: string;
198
+ out: string;
199
+ dialect: "sqlite";
200
+ } | {
195
201
  driver: string;
196
202
  dbCredentials: {
197
203
  accountId: string | undefined;
@@ -253,16 +259,16 @@ declare const createInternalError: (error: unknown, details?: {
253
259
  declare const isInternalError: (error: unknown) => error is InternalError;
254
260
 
255
261
  declare const drizzlePgConfig: {
256
- schema: string;
257
- out: string;
258
- dialect: "postgresql";
259
- dbCredentials: {
260
- url: string;
261
- };
262
262
  migrations: {
263
263
  table: string;
264
264
  schema: string;
265
265
  };
266
+ dbCredentials: {
267
+ url: string;
268
+ };
269
+ schema: string;
270
+ out: string;
271
+ dialect: "postgresql";
266
272
  };
267
273
 
268
274
  declare const calculateExponentialBackoff: (attempts: number, baseDelaySeconds: number) => number;
package/dist/index.mjs CHANGED
@@ -8,7 +8,7 @@ import { consola } from 'consola';
8
8
  import fs from 'fs';
9
9
  import crypto$1 from 'node:crypto';
10
10
  import path from 'path';
11
- import { parse } from 'jsonc-parser/lib/esm/main.js';
11
+ import { parse } from 'comment-json';
12
12
  import superjson from 'superjson';
13
13
 
14
14
  const base = {
@@ -210,6 +210,21 @@ 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
+
213
228
  function durableObjectNamespaceIdFromName(uniqueKey, name) {
214
229
  const key = crypto$1.createHash("sha256").update(uniqueKey).digest();
215
230
  const nameHmac = crypto$1.createHmac("sha256", key).update(name).digest().subarray(0, 16);
@@ -220,11 +235,7 @@ const getDatabaseIdFromWrangler = () => {
220
235
  try {
221
236
  const wranglerPath = path.resolve("./wrangler.jsonc");
222
237
  const wranglerContent = fs.readFileSync(wranglerPath, "utf-8");
223
- const errors = [];
224
- const config = parse(wranglerContent, errors, { allowTrailingComma: true });
225
- if (errors.length) {
226
- throw new Error("Invalid JSONC in wrangler.jsonc");
227
- }
238
+ const config = parse(wranglerContent);
228
239
  const environment = process.env.ENVIRONMENT || "localhost";
229
240
  let databaseId;
230
241
  if (environment !== "localhost" && config.env?.[environment]) {
@@ -249,10 +260,6 @@ const getDatabaseIdFromWrangler = () => {
249
260
  );
250
261
  }
251
262
  };
252
- const isRemoteEnvironment = () => {
253
- const environment = process.env.ENVIRONMENT;
254
- return environment && environment !== "localhost";
255
- };
256
263
  const getLocalD1 = (databaseId) => {
257
264
  const name = durableObjectNamespaceIdFromName(
258
265
  "miniflare-D1DatabaseObject",
@@ -280,7 +287,11 @@ const getLocalD1 = (databaseId) => {
280
287
  }
281
288
  }
282
289
  };
283
- const getCredentials = () => {
290
+ const getD1Credentials = () => {
291
+ const environment = process.env.ENVIRONMENT;
292
+ if (environment === "localhost") {
293
+ return {};
294
+ }
284
295
  const databaseId = getDatabaseIdFromWrangler() ?? "";
285
296
  if (isRemoteEnvironment()) {
286
297
  return {
@@ -303,7 +314,7 @@ const drizzleD1Config = {
303
314
  schema: "./src/database/schema/",
304
315
  out: "./src/database/migrations/",
305
316
  dialect: "sqlite",
306
- ...getCredentials()
317
+ ...getD1Credentials()
307
318
  };
308
319
 
309
320
  class DatabaseTransaction {
@@ -368,24 +379,26 @@ const defineCommand = (handler) => {
368
379
  });
369
380
  };
370
381
 
371
- function first(rows) {
372
- return rows.length > 0 ? rows[0] : void 0;
373
- }
374
- function firstOrError(rows) {
375
- if (rows.length === 0) {
376
- throw new Error("Query did not return any data.");
382
+ const getPgCredentials = () => {
383
+ if (isRemoteEnvironment()) {
384
+ return {
385
+ dbCredentials: {
386
+ url: process.env.DATABASE_URL
387
+ }
388
+ };
389
+ } else {
390
+ return {
391
+ dbCredentials: {
392
+ url: `postgres://db_user:db_password@127.0.0.1:${process.env.DB_LOCAL_PORT}/db`
393
+ }
394
+ };
377
395
  }
378
- return rows[0];
379
- }
380
- const uuidv4 = () => crypto.randomUUID();
381
-
396
+ };
382
397
  const drizzlePgConfig = {
383
398
  schema: "./src/database/schema/",
384
399
  out: "./src/database/migrations/",
385
400
  dialect: "postgresql",
386
- dbCredentials: {
387
- url: process.env.DATABASE_URL
388
- },
401
+ ...getPgCredentials(),
389
402
  migrations: {
390
403
  table: "__drizzle_migrations",
391
404
  schema: "public"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@develit-io/backend-sdk",
3
- "version": "5.8.2",
3
+ "version": "5.9.0",
4
4
  "description": "Develit Backend SDK",
5
5
  "author": "Develit.io",
6
6
  "license": "ISC",
@@ -22,11 +22,6 @@
22
22
  "require": "./dist/index.cjs",
23
23
  "types": "./dist/index.d.ts"
24
24
  },
25
- "./jsonc": {
26
- "import": "./dist/jsonc.mjs",
27
- "require": "./dist/jsonc.cjs",
28
- "types": "./dist/jsonc.d.ts"
29
- },
30
25
  "./package.json": "./package.json"
31
26
  },
32
27
  "main": "./dist/index.cjs",
@@ -34,12 +29,12 @@
34
29
  "files": ["dist"],
35
30
  "dependencies": {
36
31
  "@cloudflare/workers-types": "^4.20250722.0",
32
+ "comment-json": "^4.2.5",
37
33
  "consola": "^3.4.2",
38
34
  "drizzle-kit": "^0.31.4",
39
35
  "drizzle-orm": "^0.44.3",
40
36
  "h3": "^1.15.3",
41
37
  "http-status-codes": "2.3.0",
42
- "jsonc-parser": "^3.3.1",
43
38
  "superjson": "^2.2.2"
44
39
  },
45
40
  "peerDependencies": {
package/dist/jsonc.cjs DELETED
@@ -1,16 +0,0 @@
1
- 'use strict';
2
-
3
- const main_js = require('jsonc-parser/lib/esm/main.js');
4
-
5
-
6
-
7
- Object.prototype.hasOwnProperty.call(main_js, '__proto__') &&
8
- !Object.prototype.hasOwnProperty.call(exports, '__proto__') &&
9
- Object.defineProperty(exports, '__proto__', {
10
- enumerable: true,
11
- value: main_js['__proto__']
12
- });
13
-
14
- Object.keys(main_js).forEach(function (k) {
15
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = main_js[k];
16
- });
package/dist/jsonc.d.cts DELETED
@@ -1 +0,0 @@
1
- export * from 'jsonc-parser/lib/esm/main.js';
package/dist/jsonc.d.mts DELETED
@@ -1 +0,0 @@
1
- export * from 'jsonc-parser/lib/esm/main.js';
package/dist/jsonc.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from 'jsonc-parser/lib/esm/main.js';
package/dist/jsonc.mjs DELETED
@@ -1 +0,0 @@
1
- export * from 'jsonc-parser/lib/esm/main.js';