@grupodiariodaregiao/bunstone 0.7.0 → 0.7.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/AGENTS.md +124 -0
- package/dist/index.d.ts +22 -21
- package/dist/index.js +104486 -104347
- package/dist/lib/app-startup.d.ts +1 -0
- package/dist/lib/database/sql-module.d.ts +30 -10
- package/dist/lib/errors/index.d.ts +3 -1
- package/docs/database-sql.md +62 -0
- package/docs/pt-BR/database-sql.md +62 -0
- package/lib/app-startup.ts +34 -2
- package/lib/database/sql-module.ts +271 -37
- package/lib/errors/index.ts +14 -1
- package/package.json +1 -1
package/AGENTS.md
CHANGED
|
@@ -1062,6 +1062,68 @@ OR using a connection string:
|
|
|
1062
1062
|
export class AppModule {}
|
|
1063
1063
|
```
|
|
1064
1064
|
|
|
1065
|
+
### Connection options
|
|
1066
|
+
|
|
1067
|
+
You can pass a second argument with pool and client settings. Bunstone forwards only the supported options to [Bun.SQL](https://bun.sh/docs/api/sql):
|
|
1068
|
+
|
|
1069
|
+
```typescript
|
|
1070
|
+
@Module({
|
|
1071
|
+
imports: [
|
|
1072
|
+
SqlModule.register("mysql://user:pass@host:3306/db", {
|
|
1073
|
+
maxLifetime: 25200,
|
|
1074
|
+
connectionTimeout: 30,
|
|
1075
|
+
max: 10,
|
|
1076
|
+
timezone: "UTC",
|
|
1077
|
+
}),
|
|
1078
|
+
],
|
|
1079
|
+
})
|
|
1080
|
+
export class AppModule {}
|
|
1081
|
+
```
|
|
1082
|
+
|
|
1083
|
+
The same options can be combined with the object-style registration:
|
|
1084
|
+
|
|
1085
|
+
```typescript
|
|
1086
|
+
SqlModule.register({
|
|
1087
|
+
provider: "postgresql",
|
|
1088
|
+
host: "localhost",
|
|
1089
|
+
port: 5432,
|
|
1090
|
+
username: "user",
|
|
1091
|
+
password: "password",
|
|
1092
|
+
database: "my_db",
|
|
1093
|
+
max: 20,
|
|
1094
|
+
idleTimeout: 30,
|
|
1095
|
+
});
|
|
1096
|
+
```
|
|
1097
|
+
|
|
1098
|
+
For backward compatibility, the second argument may still be a timezone string:
|
|
1099
|
+
|
|
1100
|
+
```typescript
|
|
1101
|
+
SqlModule.register("mysql://user:pass@host/db", "UTC");
|
|
1102
|
+
```
|
|
1103
|
+
|
|
1104
|
+
#### Supported options (`SqlModuleOptions`)
|
|
1105
|
+
|
|
1106
|
+
| Option | Description |
|
|
1107
|
+
|---|---|
|
|
1108
|
+
| `timezone` | Bunstone helper for date/time handling. Defaults to `UTC`. Mapped to driver `connection` settings. |
|
|
1109
|
+
| `max` | Maximum connections in the pool |
|
|
1110
|
+
| `maxLifetime` | Maximum connection lifetime in seconds |
|
|
1111
|
+
| `connectionTimeout` | Timeout when establishing a connection (seconds) |
|
|
1112
|
+
| `idleTimeout` | Close idle connections after N seconds |
|
|
1113
|
+
| `connection` | Driver-specific runtime settings (e.g. PostgreSQL `TimeZone`) |
|
|
1114
|
+
| `tls` | TLS/SSL configuration |
|
|
1115
|
+
| `prepare` | Enable automatic prepared statements |
|
|
1116
|
+
| `bigint` | Return out-of-range integers as `BigInt` |
|
|
1117
|
+
| `onconnect` | Callback when a connection attempt completes |
|
|
1118
|
+
| `onclose` | Callback when a connection closes |
|
|
1119
|
+
| `path` | Unix domain socket path |
|
|
1120
|
+
| `readonly` | SQLite read-only mode |
|
|
1121
|
+
| `create` | SQLite create-if-missing behavior |
|
|
1122
|
+
| `safeIntegers` | SQLite safe integer handling |
|
|
1123
|
+
| `strict` | SQLite strict mode |
|
|
1124
|
+
|
|
1125
|
+
Only the options listed above are accepted. Invalid keys are rejected by TypeScript and also throw `DatabaseError` (`BNS-DB-003`) at runtime.
|
|
1126
|
+
|
|
1065
1127
|
## Usage
|
|
1066
1128
|
|
|
1067
1129
|
Once registered, the `SqlService` is globally available. You can inject it into any controller or provider without needing to import `SqlModule` into subsequent modules.
|
|
@@ -3943,6 +4005,68 @@ OU usando uma string de conexão:
|
|
|
3943
4005
|
export class AppModule {}
|
|
3944
4006
|
```
|
|
3945
4007
|
|
|
4008
|
+
### Opções de conexão
|
|
4009
|
+
|
|
4010
|
+
Você pode passar um segundo argumento com configurações de pool e do client. O Bunstone repassa apenas as opções suportadas para o [Bun.SQL](https://bun.sh/docs/api/sql):
|
|
4011
|
+
|
|
4012
|
+
```typescript
|
|
4013
|
+
@Module({
|
|
4014
|
+
imports: [
|
|
4015
|
+
SqlModule.register("mysql://user:pass@host:3306/db", {
|
|
4016
|
+
maxLifetime: 25200,
|
|
4017
|
+
connectionTimeout: 30,
|
|
4018
|
+
max: 10,
|
|
4019
|
+
timezone: "UTC",
|
|
4020
|
+
}),
|
|
4021
|
+
],
|
|
4022
|
+
})
|
|
4023
|
+
export class AppModule {}
|
|
4024
|
+
```
|
|
4025
|
+
|
|
4026
|
+
As mesmas opções podem ser usadas no registro via objeto:
|
|
4027
|
+
|
|
4028
|
+
```typescript
|
|
4029
|
+
SqlModule.register({
|
|
4030
|
+
provider: "postgresql",
|
|
4031
|
+
host: "localhost",
|
|
4032
|
+
port: 5432,
|
|
4033
|
+
username: "user",
|
|
4034
|
+
password: "password",
|
|
4035
|
+
database: "my_db",
|
|
4036
|
+
max: 20,
|
|
4037
|
+
idleTimeout: 30,
|
|
4038
|
+
});
|
|
4039
|
+
```
|
|
4040
|
+
|
|
4041
|
+
Por compatibilidade, o segundo argumento ainda pode ser uma string de timezone:
|
|
4042
|
+
|
|
4043
|
+
```typescript
|
|
4044
|
+
SqlModule.register("mysql://user:pass@host/db", "UTC");
|
|
4045
|
+
```
|
|
4046
|
+
|
|
4047
|
+
#### Opções suportadas (`SqlModuleOptions`)
|
|
4048
|
+
|
|
4049
|
+
| Opção | Descrição |
|
|
4050
|
+
|---|---|
|
|
4051
|
+
| `timezone` | Helper do Bunstone para datas/horas. Padrão: `UTC`. Mapeado para `connection` do driver. |
|
|
4052
|
+
| `max` | Máximo de conexões no pool |
|
|
4053
|
+
| `maxLifetime` | Tempo máximo de vida da conexão em segundos |
|
|
4054
|
+
| `connectionTimeout` | Timeout ao estabelecer conexão (segundos) |
|
|
4055
|
+
| `idleTimeout` | Fecha conexões ociosas após N segundos |
|
|
4056
|
+
| `connection` | Configurações runtime do driver (ex.: `TimeZone` no PostgreSQL) |
|
|
4057
|
+
| `tls` | Configuração TLS/SSL |
|
|
4058
|
+
| `prepare` | Habilita prepared statements automáticos |
|
|
4059
|
+
| `bigint` | Retorna inteiros fora do range como `BigInt` |
|
|
4060
|
+
| `onconnect` | Callback ao concluir tentativa de conexão |
|
|
4061
|
+
| `onclose` | Callback ao fechar conexão |
|
|
4062
|
+
| `path` | Caminho do Unix domain socket |
|
|
4063
|
+
| `readonly` | Modo somente leitura (SQLite) |
|
|
4064
|
+
| `create` | Comportamento de criação do arquivo (SQLite) |
|
|
4065
|
+
| `safeIntegers` | Tratamento seguro de inteiros (SQLite) |
|
|
4066
|
+
| `strict` | Modo strict (SQLite) |
|
|
4067
|
+
|
|
4068
|
+
Somente as opções listadas acima são aceitas. Chaves inválidas são rejeitadas pelo TypeScript e também lançam `DatabaseError` (`BNS-DB-003`) em runtime.
|
|
4069
|
+
|
|
3946
4070
|
## Uso
|
|
3947
4071
|
|
|
3948
4072
|
Depois de registrado, o `SqlService` fica disponível globalmente. Você pode injetá-lo em qualquer controller ou provider sem precisar importar o `SqlModule` nos módulos subsequentes.
|
package/dist/index.d.ts
CHANGED
|
@@ -13,14 +13,15 @@ import "reflect-metadata";
|
|
|
13
13
|
* Nunca deixe uma nova feature da lib sem a respectiva entrada aqui.
|
|
14
14
|
*/
|
|
15
15
|
export * from "./lib/adapters/cache-adapter";
|
|
16
|
-
export { EmailModule, EmailService } from "./lib/email/email-module";
|
|
17
|
-
export { EmailLayout } from "./lib/email/email-layout";
|
|
18
16
|
export * from "./lib/adapters/form-data";
|
|
19
17
|
export * from "./lib/adapters/upload-adapter";
|
|
20
18
|
export * from "./lib/app-startup";
|
|
19
|
+
export { BullMqModule } from "./lib/bullmq/bullmq-module";
|
|
20
|
+
export * from "./lib/bullmq/decorators/process.decorator";
|
|
21
|
+
export * from "./lib/bullmq/decorators/processor.decorator";
|
|
22
|
+
export { QueueService } from "./lib/bullmq/queue.service";
|
|
21
23
|
export * from "./lib/components/layout";
|
|
22
24
|
export * from "./lib/controller";
|
|
23
|
-
export * from "./lib/ratelimit";
|
|
24
25
|
export * from "./lib/cqrs/command-bus";
|
|
25
26
|
export * from "./lib/cqrs/cqrs-module";
|
|
26
27
|
export * from "./lib/cqrs/decorators/command-handler.decorator";
|
|
@@ -33,44 +34,44 @@ export * from "./lib/cqrs/interfaces/event.interface";
|
|
|
33
34
|
export * from "./lib/cqrs/interfaces/query.interface";
|
|
34
35
|
export * from "./lib/cqrs/query-bus";
|
|
35
36
|
export { SqlModule, SqlService } from "./lib/database/sql-module";
|
|
36
|
-
export {
|
|
37
|
-
export {
|
|
38
|
-
export
|
|
39
|
-
export * from "./lib/bullmq/decorators/process.decorator";
|
|
40
|
-
export { RabbitMQModule } from "./lib/rabbitmq/rabbitmq-module";
|
|
41
|
-
export { RabbitMQService } from "./lib/rabbitmq/rabbitmq.service";
|
|
42
|
-
export { RabbitMQDeadLetterService } from "./lib/rabbitmq/dead-letter.service";
|
|
43
|
-
export { RabbitMQConnection } from "./lib/rabbitmq/rabbitmq-connection";
|
|
44
|
-
export * from "./lib/rabbitmq/decorators/consumer.decorator";
|
|
45
|
-
export * from "./lib/rabbitmq/decorators/subscribe.decorator";
|
|
46
|
-
export type * from "./lib/rabbitmq/interfaces/rabbitmq-options.interface";
|
|
47
|
-
export type * from "./lib/rabbitmq/interfaces/rabbitmq-message.interface";
|
|
37
|
+
export type { BunSqlClientOptions, ConnectionOptions, SqlConnectionDetails, SqlConnectionOptions, SqlModuleOptions, SqlPoolOptions, SqlRegisterOptions, } from "./lib/database/sql-module";
|
|
38
|
+
export { EmailLayout } from "./lib/email/email-layout";
|
|
39
|
+
export { EmailModule, EmailService } from "./lib/email/email-module";
|
|
48
40
|
export * from "./lib/errors";
|
|
49
|
-
export { ErrorFormatter } from "./lib/utils/error-formatter";
|
|
50
41
|
export * from "./lib/guard";
|
|
51
42
|
export * from "./lib/http-exceptions";
|
|
52
43
|
export * from "./lib/http-methods";
|
|
53
44
|
export * from "./lib/http-params";
|
|
54
45
|
export * from "./lib/injectable";
|
|
46
|
+
export type { GuardContract } from "./lib/interfaces/guard-contract";
|
|
55
47
|
export * from "./lib/jwt";
|
|
56
48
|
export * from "./lib/jwt/jwt-module";
|
|
57
49
|
export { JwtService } from "./lib/jwt/jwt.service";
|
|
58
50
|
export * from "./lib/module";
|
|
59
51
|
export * from "./lib/on-module";
|
|
60
52
|
export * from "./lib/openapi";
|
|
53
|
+
export { RabbitMQDeadLetterService } from "./lib/rabbitmq/dead-letter.service";
|
|
54
|
+
export * from "./lib/rabbitmq/decorators/consumer.decorator";
|
|
55
|
+
export * from "./lib/rabbitmq/decorators/subscribe.decorator";
|
|
56
|
+
export type * from "./lib/rabbitmq/interfaces/rabbitmq-message.interface";
|
|
57
|
+
export type * from "./lib/rabbitmq/interfaces/rabbitmq-options.interface";
|
|
58
|
+
export { RabbitMQConnection } from "./lib/rabbitmq/rabbitmq-connection";
|
|
59
|
+
export { RabbitMQModule } from "./lib/rabbitmq/rabbitmq-module";
|
|
60
|
+
export { RabbitMQService } from "./lib/rabbitmq/rabbitmq.service";
|
|
61
|
+
export * from "./lib/ratelimit";
|
|
61
62
|
export * from "./lib/render";
|
|
62
|
-
export * from "./lib/types/options";
|
|
63
|
-
export * from "./lib/types/module-config";
|
|
64
63
|
export * from "./lib/schedule/cron/cron";
|
|
65
64
|
export * from "./lib/schedule/timeout/timeout";
|
|
65
|
+
export type { OtlpExporterOptions, TelemetryOptions } from "./lib/telemetry/interfaces/telemetry-options.interface";
|
|
66
66
|
export { TelemetryModule } from "./lib/telemetry/telemetry-module";
|
|
67
67
|
export { TelemetrySdk } from "./lib/telemetry/telemetry.sdk";
|
|
68
|
-
export type { TelemetryOptions, OtlpExporterOptions } from "./lib/telemetry/interfaces/telemetry-options.interface";
|
|
69
68
|
export * from "./lib/testing/test";
|
|
70
|
-
export * from "./lib/testing/testing-module";
|
|
71
69
|
export * from "./lib/testing/test-app";
|
|
70
|
+
export * from "./lib/testing/testing-module";
|
|
72
71
|
export type { HttpRequest } from "./lib/types/http-request";
|
|
72
|
+
export * from "./lib/types/module-config";
|
|
73
73
|
export type { ModuleConfig } from "./lib/types/module-config";
|
|
74
|
+
export * from "./lib/types/options";
|
|
74
75
|
export type { Options } from "./lib/types/options";
|
|
76
|
+
export { ErrorFormatter } from "./lib/utils/error-formatter";
|
|
75
77
|
export * from "./lib/utils/logger";
|
|
76
|
-
export type { GuardContract } from "./lib/interfaces/guard-contract";
|