@grupodiariodaregiao/bunstone 0.4.7 → 0.5.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/bin/cli.ts +22 -12
- package/dist/index.js +29 -6
- package/lib/database/sql-module.ts +44 -4
- package/package.json +1 -1
package/bin/cli.ts
CHANGED
|
@@ -23,18 +23,6 @@ const THIN = "─".repeat(64);
|
|
|
23
23
|
const args = Bun.argv.slice(2);
|
|
24
24
|
const command = args[0];
|
|
25
25
|
|
|
26
|
-
// ── Command dispatch ──────────────────────────────────────────────────────────
|
|
27
|
-
if (command === "run") {
|
|
28
|
-
await runCommand(args.slice(1));
|
|
29
|
-
} else if (command === "exports") {
|
|
30
|
-
await exportsCommand();
|
|
31
|
-
} else if (command === "new" || (command && !args[1])) {
|
|
32
|
-
await scaffold(command === "new" ? args[1] : command);
|
|
33
|
-
} else {
|
|
34
|
-
printHelp();
|
|
35
|
-
process.exit(1);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
26
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
39
27
|
// bunstone run [bun-flags...] <entrypoint>
|
|
40
28
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
@@ -535,3 +523,25 @@ ${cyan("Examples:")}
|
|
|
535
523
|
bunstone run --watch src/main.ts
|
|
536
524
|
`);
|
|
537
525
|
}
|
|
526
|
+
|
|
527
|
+
async function main() {
|
|
528
|
+
if (command === "run") {
|
|
529
|
+
await runCommand(args.slice(1));
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
if (command === "exports") {
|
|
534
|
+
await exportsCommand();
|
|
535
|
+
return;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
if (command === "new" || (command && !args[1])) {
|
|
539
|
+
await scaffold(command === "new" ? args[1] : command);
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
printHelp();
|
|
544
|
+
process.exit(1);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
await main();
|
package/dist/index.js
CHANGED
|
@@ -16746,7 +16746,7 @@ WD9f
|
|
|
16746
16746
|
|
|
16747
16747
|
// node_modules/ioredis/built/utils/index.js
|
|
16748
16748
|
var require_utils2 = __commonJS((exports) => {
|
|
16749
|
-
var __dirname = "/home/filipi.oliveira@gdc.local/poc/
|
|
16749
|
+
var __dirname = "/home/filipi.oliveira@gdc.local/poc/bunstone/node_modules/ioredis/built/utils";
|
|
16750
16750
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16751
16751
|
exports.noop = exports.defaults = exports.Debug = exports.getPackageMeta = exports.zipMap = exports.CONNECTION_CLOSED_ERROR_MSG = exports.shuffle = exports.sample = exports.resolveTLSProfile = exports.parseURL = exports.optimizeErrorStack = exports.toArg = exports.convertMapToArray = exports.convertObjectToArray = exports.timeout = exports.packObject = exports.isInt = exports.wrapMultiResult = exports.convertBufferToString = undefined;
|
|
16752
16752
|
var fs_1 = __require("fs");
|
|
@@ -17032,7 +17032,7 @@ var require_argumentParsers = __commonJS((exports) => {
|
|
|
17032
17032
|
|
|
17033
17033
|
// node_modules/ioredis/built/Command.js
|
|
17034
17034
|
var require_Command = __commonJS((exports) => {
|
|
17035
|
-
var __dirname = "/home/filipi.oliveira@gdc.local/poc/
|
|
17035
|
+
var __dirname = "/home/filipi.oliveira@gdc.local/poc/bunstone/node_modules/ioredis/built";
|
|
17036
17036
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17037
17037
|
var commands_1 = require_built();
|
|
17038
17038
|
var calculateSlot = require_lib();
|
|
@@ -24996,7 +24996,7 @@ var require_node_gyp_build_optional_packages = __commonJS((exports, module) => {
|
|
|
24996
24996
|
|
|
24997
24997
|
// node_modules/msgpackr-extract/index.js
|
|
24998
24998
|
var require_msgpackr_extract = __commonJS((exports, module) => {
|
|
24999
|
-
var __dirname = "/home/filipi.oliveira@gdc.local/poc/
|
|
24999
|
+
var __dirname = "/home/filipi.oliveira@gdc.local/poc/bunstone/node_modules/msgpackr-extract";
|
|
25000
25000
|
module.exports = require_node_gyp_build_optional_packages()(__dirname);
|
|
25001
25001
|
});
|
|
25002
25002
|
|
|
@@ -31911,7 +31911,7 @@ var require_pattern_validation = __commonJS((exports) => {
|
|
|
31911
31911
|
|
|
31912
31912
|
// node_modules/node-cron/dist/esm/tasks/background-scheduled-task/background-scheduled-task.js
|
|
31913
31913
|
var require_background_scheduled_task = __commonJS((exports) => {
|
|
31914
|
-
var __dirname = "/home/filipi.oliveira@gdc.local/poc/
|
|
31914
|
+
var __dirname = "/home/filipi.oliveira@gdc.local/poc/bunstone/node_modules/node-cron/dist/esm/tasks/background-scheduled-task";
|
|
31915
31915
|
var __importDefault2 = exports && exports.__importDefault || function(mod) {
|
|
31916
31916
|
return mod && mod.__esModule ? mod : { default: mod };
|
|
31917
31917
|
};
|
|
@@ -32135,7 +32135,7 @@ var require_background_scheduled_task = __commonJS((exports) => {
|
|
|
32135
32135
|
|
|
32136
32136
|
// node_modules/node-cron/dist/esm/node-cron.js
|
|
32137
32137
|
var require_node_cron = __commonJS((exports) => {
|
|
32138
|
-
var __filename = "/home/filipi.oliveira@gdc.local/poc/
|
|
32138
|
+
var __filename = "/home/filipi.oliveira@gdc.local/poc/bunstone/node_modules/node-cron/dist/esm/node-cron.js";
|
|
32139
32139
|
var __importDefault2 = exports && exports.__importDefault || function(mod) {
|
|
32140
32140
|
return mod && mod.__esModule ? mod : { default: mod };
|
|
32141
32141
|
};
|
|
@@ -118496,6 +118496,25 @@ CqrsModule = __legacyDecorateClassTS([
|
|
|
118496
118496
|
], CqrsModule);
|
|
118497
118497
|
// lib/database/sql-module.ts
|
|
118498
118498
|
var {SQL } = globalThis.Bun;
|
|
118499
|
+
function detectProvider(url2) {
|
|
118500
|
+
if (url2.startsWith("mysql://") || url2.startsWith("mysql2://")) {
|
|
118501
|
+
return "mysql";
|
|
118502
|
+
}
|
|
118503
|
+
if (url2 === ":memory:" || url2.startsWith("sqlite://") || url2.startsWith("sqlite:") || url2.startsWith("file://") || url2.startsWith("file:")) {
|
|
118504
|
+
return "sqlite";
|
|
118505
|
+
}
|
|
118506
|
+
return "postgresql";
|
|
118507
|
+
}
|
|
118508
|
+
function buildConnectionConfig(provider) {
|
|
118509
|
+
if (provider === "postgresql") {
|
|
118510
|
+
return { TimeZone: "UTC" };
|
|
118511
|
+
}
|
|
118512
|
+
if (provider === "mysql") {
|
|
118513
|
+
return { time_zone: "+00:00" };
|
|
118514
|
+
}
|
|
118515
|
+
return;
|
|
118516
|
+
}
|
|
118517
|
+
|
|
118499
118518
|
class SqlService {
|
|
118500
118519
|
async query(query, params) {
|
|
118501
118520
|
const sql = this.getSqlInstance();
|
|
@@ -118528,8 +118547,12 @@ SqlService = __legacyDecorateClassTS([
|
|
|
118528
118547
|
class SqlModule {
|
|
118529
118548
|
static sqlInstance;
|
|
118530
118549
|
static register(connection2) {
|
|
118550
|
+
const url2 = typeof connection2 === "string" ? connection2 : `${connection2.provider}://${connection2.username}:${connection2.password}@${connection2.host}:${connection2.port}/${connection2.database}`;
|
|
118551
|
+
const provider = typeof connection2 === "string" ? detectProvider(connection2) : connection2.provider;
|
|
118552
|
+
const connectionConfig = buildConnectionConfig(provider);
|
|
118531
118553
|
SqlModule.sqlInstance = new SQL({
|
|
118532
|
-
url:
|
|
118554
|
+
url: url2,
|
|
118555
|
+
...connectionConfig && { connection: connectionConfig }
|
|
118533
118556
|
});
|
|
118534
118557
|
return SqlModule;
|
|
118535
118558
|
}
|
|
@@ -12,6 +12,36 @@ type ConnectionOptions = {
|
|
|
12
12
|
provider: "postgresql" | "mysql" | "sqlite";
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
+
type Provider = "postgresql" | "mysql" | "sqlite";
|
|
16
|
+
|
|
17
|
+
function detectProvider(url: string): Provider {
|
|
18
|
+
if (url.startsWith("mysql://") || url.startsWith("mysql2://")) {
|
|
19
|
+
return "mysql";
|
|
20
|
+
}
|
|
21
|
+
if (
|
|
22
|
+
url === ":memory:" ||
|
|
23
|
+
url.startsWith("sqlite://") ||
|
|
24
|
+
url.startsWith("sqlite:") ||
|
|
25
|
+
url.startsWith("file://") ||
|
|
26
|
+
url.startsWith("file:")
|
|
27
|
+
) {
|
|
28
|
+
return "sqlite";
|
|
29
|
+
}
|
|
30
|
+
return "postgresql";
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function buildConnectionConfig(
|
|
34
|
+
provider: Provider,
|
|
35
|
+
): Record<string, string | boolean | number> | undefined {
|
|
36
|
+
if (provider === "postgresql") {
|
|
37
|
+
return { TimeZone: "UTC" };
|
|
38
|
+
}
|
|
39
|
+
if (provider === "mysql") {
|
|
40
|
+
return { time_zone: "+00:00" };
|
|
41
|
+
}
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
|
|
15
45
|
@Injectable()
|
|
16
46
|
export class SqlService {
|
|
17
47
|
async query<T = any>(query: string, params?: any[]): Promise<T[]> {
|
|
@@ -54,11 +84,21 @@ export class SqlModule {
|
|
|
54
84
|
static register(connection: ConnectionOptions): typeof SqlModule;
|
|
55
85
|
static register(connection: string): typeof SqlModule;
|
|
56
86
|
static register(connection: string | ConnectionOptions) {
|
|
87
|
+
const url =
|
|
88
|
+
typeof connection === "string"
|
|
89
|
+
? connection
|
|
90
|
+
: `${connection.provider}://${connection.username}:${connection.password}@${connection.host}:${connection.port}/${connection.database}`;
|
|
91
|
+
|
|
92
|
+
const provider =
|
|
93
|
+
typeof connection === "string"
|
|
94
|
+
? detectProvider(connection)
|
|
95
|
+
: connection.provider;
|
|
96
|
+
|
|
97
|
+
const connectionConfig = buildConnectionConfig(provider);
|
|
98
|
+
|
|
57
99
|
SqlModule.sqlInstance = new SQL({
|
|
58
|
-
url
|
|
59
|
-
|
|
60
|
-
? connection
|
|
61
|
-
: `${connection.provider}://${connection.username}:${connection.password}@${connection.host}:${connection.port}/${connection.database}`,
|
|
100
|
+
url,
|
|
101
|
+
...(connectionConfig && { connection: connectionConfig }),
|
|
62
102
|
});
|
|
63
103
|
|
|
64
104
|
return SqlModule;
|