@venizia/ignis-docs 0.0.7-2 → 0.0.8-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.
Files changed (161) hide show
  1. package/dist/mcp-server/common/paths.d.ts +4 -2
  2. package/dist/mcp-server/common/paths.d.ts.map +1 -1
  3. package/dist/mcp-server/common/paths.js +8 -6
  4. package/dist/mcp-server/common/paths.js.map +1 -1
  5. package/dist/mcp-server/tools/docs/get-document-content.tool.d.ts +1 -1
  6. package/dist/mcp-server/tools/docs/get-document-content.tool.d.ts.map +1 -1
  7. package/dist/mcp-server/tools/docs/get-document-content.tool.js +7 -7
  8. package/dist/mcp-server/tools/docs/get-document-metadata.tool.js +3 -3
  9. package/dist/mcp-server/tools/docs/get-package-overview.tool.d.ts +1 -1
  10. package/dist/mcp-server/tools/docs/get-package-overview.tool.js +1 -1
  11. package/package.json +1 -1
  12. package/wiki/best-practices/api-usage-examples.md +9 -9
  13. package/wiki/best-practices/architectural-patterns.md +19 -3
  14. package/wiki/best-practices/architecture-decisions.md +6 -6
  15. package/wiki/best-practices/code-style-standards/advanced-patterns.md +1 -1
  16. package/wiki/best-practices/code-style-standards/control-flow.md +1 -1
  17. package/wiki/best-practices/code-style-standards/function-patterns.md +2 -2
  18. package/wiki/best-practices/code-style-standards/index.md +2 -2
  19. package/wiki/best-practices/code-style-standards/naming-conventions.md +1 -1
  20. package/wiki/best-practices/code-style-standards/route-definitions.md +4 -4
  21. package/wiki/best-practices/data-modeling.md +1 -1
  22. package/wiki/best-practices/deployment-strategies.md +1 -1
  23. package/wiki/best-practices/error-handling.md +2 -2
  24. package/wiki/best-practices/performance-optimization.md +3 -3
  25. package/wiki/best-practices/security-guidelines.md +2 -2
  26. package/wiki/best-practices/troubleshooting-tips.md +1 -1
  27. package/wiki/{references → extensions}/components/authentication/api.md +12 -20
  28. package/wiki/{references → extensions}/components/authentication/errors.md +1 -1
  29. package/wiki/{references → extensions}/components/authentication/index.md +5 -8
  30. package/wiki/{references → extensions}/components/authentication/usage.md +20 -36
  31. package/wiki/{references → extensions}/components/authorization/api.md +62 -13
  32. package/wiki/{references → extensions}/components/authorization/errors.md +12 -7
  33. package/wiki/{references → extensions}/components/authorization/index.md +93 -6
  34. package/wiki/{references → extensions}/components/authorization/usage.md +42 -4
  35. package/wiki/{references → extensions}/components/health-check.md +5 -4
  36. package/wiki/{references → extensions}/components/index.md +2 -0
  37. package/wiki/{references → extensions}/components/mail/index.md +1 -1
  38. package/wiki/{references → extensions}/components/request-tracker.md +1 -1
  39. package/wiki/{references → extensions}/components/socket-io/api.md +2 -2
  40. package/wiki/{references → extensions}/components/socket-io/errors.md +2 -0
  41. package/wiki/{references → extensions}/components/socket-io/index.md +24 -20
  42. package/wiki/{references → extensions}/components/socket-io/usage.md +2 -2
  43. package/wiki/{references → extensions}/components/static-asset/api.md +14 -15
  44. package/wiki/{references → extensions}/components/static-asset/errors.md +3 -1
  45. package/wiki/{references → extensions}/components/static-asset/index.md +158 -89
  46. package/wiki/{references → extensions}/components/static-asset/usage.md +8 -5
  47. package/wiki/{references → extensions}/components/swagger.md +3 -3
  48. package/wiki/{references → extensions}/components/template/index.md +4 -4
  49. package/wiki/{references → extensions}/components/template/setup-page.md +1 -1
  50. package/wiki/{references → extensions}/components/template/single-page.md +1 -1
  51. package/wiki/{references → extensions}/components/websocket/api.md +7 -6
  52. package/wiki/{references → extensions}/components/websocket/errors.md +17 -3
  53. package/wiki/{references → extensions}/components/websocket/index.md +17 -11
  54. package/wiki/{references → extensions}/components/websocket/usage.md +2 -2
  55. package/wiki/{references → extensions}/helpers/crypto/index.md +1 -1
  56. package/wiki/{references → extensions}/helpers/env/index.md +9 -5
  57. package/wiki/{references → extensions}/helpers/error/index.md +2 -7
  58. package/wiki/{references → extensions}/helpers/index.md +18 -6
  59. package/wiki/{references → extensions}/helpers/kafka/admin.md +33 -16
  60. package/wiki/extensions/helpers/kafka/consumer.md +384 -0
  61. package/wiki/extensions/helpers/kafka/examples.md +361 -0
  62. package/wiki/extensions/helpers/kafka/index.md +639 -0
  63. package/wiki/{references → extensions}/helpers/kafka/producer.md +100 -96
  64. package/wiki/extensions/helpers/kafka/schema-registry.md +214 -0
  65. package/wiki/{references → extensions}/helpers/logger/index.md +2 -2
  66. package/wiki/{references → extensions}/helpers/queue/index.md +400 -4
  67. package/wiki/{references → extensions}/helpers/storage/api.md +170 -10
  68. package/wiki/{references → extensions}/helpers/storage/index.md +44 -8
  69. package/wiki/{references → extensions}/helpers/template/index.md +1 -1
  70. package/wiki/{references → extensions}/helpers/testing/index.md +4 -4
  71. package/wiki/{references → extensions}/helpers/types/index.md +63 -16
  72. package/wiki/{references → extensions}/helpers/websocket/index.md +1 -1
  73. package/wiki/extensions/index.md +48 -0
  74. package/wiki/guides/core-concepts/application/bootstrapping.md +55 -37
  75. package/wiki/guides/core-concepts/application/index.md +95 -35
  76. package/wiki/guides/core-concepts/components-guide.md +23 -19
  77. package/wiki/guides/core-concepts/components.md +34 -10
  78. package/wiki/guides/core-concepts/dependency-injection.md +99 -34
  79. package/wiki/guides/core-concepts/grpc-controllers.md +295 -0
  80. package/wiki/guides/core-concepts/persistent/datasources.md +27 -8
  81. package/wiki/guides/core-concepts/persistent/models.md +43 -1
  82. package/wiki/guides/core-concepts/persistent/repositories.md +75 -8
  83. package/wiki/guides/core-concepts/persistent/transactions.md +38 -8
  84. package/wiki/guides/core-concepts/{controllers.md → rest-controllers.md} +30 -33
  85. package/wiki/guides/core-concepts/services.md +19 -5
  86. package/wiki/guides/get-started/5-minute-quickstart.md +6 -7
  87. package/wiki/guides/get-started/philosophy.md +1 -1
  88. package/wiki/guides/index.md +2 -2
  89. package/wiki/guides/reference/glossary.md +7 -7
  90. package/wiki/guides/reference/mcp-docs-server.md +1 -1
  91. package/wiki/guides/tutorials/building-a-crud-api.md +2 -2
  92. package/wiki/guides/tutorials/complete-installation.md +17 -14
  93. package/wiki/guides/tutorials/ecommerce-api.md +18 -18
  94. package/wiki/guides/tutorials/realtime-chat.md +8 -8
  95. package/wiki/guides/tutorials/testing.md +2 -2
  96. package/wiki/index.md +4 -3
  97. package/wiki/references/base/application.md +341 -21
  98. package/wiki/references/base/bootstrapping.md +43 -13
  99. package/wiki/references/base/components.md +259 -8
  100. package/wiki/references/base/controllers.md +556 -253
  101. package/wiki/references/base/datasources.md +159 -79
  102. package/wiki/references/base/dependency-injection.md +299 -48
  103. package/wiki/references/base/filter-system/application-usage.md +18 -2
  104. package/wiki/references/base/filter-system/array-operators.md +14 -6
  105. package/wiki/references/base/filter-system/comparison-operators.md +9 -3
  106. package/wiki/references/base/filter-system/default-filter.md +28 -3
  107. package/wiki/references/base/filter-system/fields-order-pagination.md +17 -13
  108. package/wiki/references/base/filter-system/index.md +169 -11
  109. package/wiki/references/base/filter-system/json-filtering.md +51 -18
  110. package/wiki/references/base/filter-system/list-operators.md +4 -3
  111. package/wiki/references/base/filter-system/logical-operators.md +7 -2
  112. package/wiki/references/base/filter-system/null-operators.md +50 -0
  113. package/wiki/references/base/filter-system/quick-reference.md +82 -243
  114. package/wiki/references/base/filter-system/range-operators.md +7 -1
  115. package/wiki/references/base/filter-system/tips.md +34 -7
  116. package/wiki/references/base/filter-system/use-cases.md +6 -5
  117. package/wiki/references/base/grpc-controllers.md +984 -0
  118. package/wiki/references/base/index.md +32 -24
  119. package/wiki/references/base/middleware.md +347 -0
  120. package/wiki/references/base/models.md +390 -46
  121. package/wiki/references/base/providers.md +14 -14
  122. package/wiki/references/base/repositories/advanced.md +84 -69
  123. package/wiki/references/base/repositories/index.md +447 -12
  124. package/wiki/references/base/repositories/mixins.md +103 -98
  125. package/wiki/references/base/repositories/relations.md +129 -45
  126. package/wiki/references/base/repositories/soft-deletable.md +104 -23
  127. package/wiki/references/base/services.md +94 -14
  128. package/wiki/references/index.md +12 -10
  129. package/wiki/references/quick-reference.md +98 -65
  130. package/wiki/references/utilities/crypto.md +21 -4
  131. package/wiki/references/utilities/date.md +25 -7
  132. package/wiki/references/utilities/index.md +26 -24
  133. package/wiki/references/utilities/jsx.md +54 -54
  134. package/wiki/references/utilities/module.md +8 -6
  135. package/wiki/references/utilities/parse.md +16 -9
  136. package/wiki/references/utilities/performance.md +22 -7
  137. package/wiki/references/utilities/promise.md +19 -16
  138. package/wiki/references/utilities/request.md +48 -26
  139. package/wiki/references/utilities/schema.md +69 -6
  140. package/wiki/references/utilities/statuses.md +131 -140
  141. package/wiki/references/helpers/kafka/consumer.md +0 -473
  142. package/wiki/references/helpers/kafka/examples.md +0 -234
  143. package/wiki/references/helpers/kafka/index.md +0 -482
  144. /package/wiki/{references → extensions}/components/mail/api.md +0 -0
  145. /package/wiki/{references → extensions}/components/mail/errors.md +0 -0
  146. /package/wiki/{references → extensions}/components/mail/usage.md +0 -0
  147. /package/wiki/{references → extensions}/components/template/api-page.md +0 -0
  148. /package/wiki/{references → extensions}/components/template/errors-page.md +0 -0
  149. /package/wiki/{references → extensions}/components/template/usage-page.md +0 -0
  150. /package/wiki/{references → extensions}/helpers/cron/index.md +0 -0
  151. /package/wiki/{references → extensions}/helpers/inversion/index.md +0 -0
  152. /package/wiki/{references → extensions}/helpers/network/api.md +0 -0
  153. /package/wiki/{references → extensions}/helpers/network/index.md +0 -0
  154. /package/wiki/{references → extensions}/helpers/redis/index.md +0 -0
  155. /package/wiki/{references → extensions}/helpers/socket-io/api.md +0 -0
  156. /package/wiki/{references → extensions}/helpers/socket-io/index.md +0 -0
  157. /package/wiki/{references → extensions}/helpers/template/single-page.md +0 -0
  158. /package/wiki/{references → extensions}/helpers/uid/index.md +0 -0
  159. /package/wiki/{references → extensions}/helpers/websocket/api.md +0 -0
  160. /package/wiki/{references → extensions}/helpers/worker-thread/index.md +0 -0
  161. /package/wiki/{references → extensions}/src-details/mcp-server.md +0 -0
@@ -15,10 +15,10 @@ Technical reference for DataSource classes - managing database connections in Ig
15
15
  | Class/Interface | Purpose | Key Members |
16
16
  |-----------------|---------|-------------|
17
17
  | **IDataSource** | Contract for all datasources | `name`, `settings`, `connector`, `getSchema()`, `configure()`, `beginTransaction()` |
18
- | **AbstractDataSource** | Base implementation with logging | Extends `BaseHelper` |
19
- | **BaseDataSource** | Concrete class to extend | Auto-discovery, driver from decorator, transaction support |
20
- | **ITransaction** | Transaction object | `connector`, `isActive`, `commit()`, `rollback()` |
21
- | **IsolationLevels** | Isolation level constants | `READ_UNCOMMITTED`, `READ_COMMITTED`, `REPEATABLE_READ`, `SERIALIZABLE` |
18
+ | **AbstractDataSource** | Base implementation with logging | Extends `BaseHelper`, declares abstract methods |
19
+ | **BaseDataSource** | Concrete class to extend | Auto-discovery, transaction support, constructor with config |
20
+ | **ITransaction** | Transaction object | `connector`, `isActive`, `isolationLevel`, `commit()`, `rollback()` |
21
+ | **IsolationLevels** | Isolation level constants | `READ_COMMITTED`, `REPEATABLE_READ`, `SERIALIZABLE` |
22
22
 
23
23
  ## `IDataSource` Interface
24
24
 
@@ -26,20 +26,36 @@ Contract for all datasource classes in the framework.
26
26
 
27
27
  **File:** `packages/core/src/base/datasources/common/types.ts`
28
28
 
29
+ ### Type Parameters
30
+
31
+ ```typescript
32
+ interface IDataSource<
33
+ Settings extends object = {},
34
+ Schema extends TAnyDataSourceSchema = TAnyDataSourceSchema,
35
+ ConfigurableOptions extends object = {},
36
+ > extends IConfigurable<ConfigurableOptions>
37
+ ```
38
+
39
+ | Type Parameter | Default | Description |
40
+ |----------------|---------|-------------|
41
+ | `Settings` | `{}` | Connection configuration type (host, port, etc.) |
42
+ | `Schema` | `TAnyDataSourceSchema` | Combined Drizzle schema type (tables + relations) |
43
+ | `ConfigurableOptions` | `{}` | Options passed to `configure()` |
44
+
29
45
  ### Properties & Methods
30
46
 
31
47
  | Member | Type | Description |
32
48
  |--------|------|-------------|
33
49
  | `name` | `string` | Datasource name |
34
- | `settings` | `object` | Configuration object |
35
- | `connector` | `TNodePostgresConnector` | Database connector instance (Drizzle) |
50
+ | `settings` | `Settings` | Configuration object |
51
+ | `connector` | `TNodePostgresConnector<Schema>` | Drizzle ORM connector instance |
36
52
  | `schema` | `Schema` | Combined Drizzle schema (auto-discovered or manual) |
37
- | `getSchema()` | Method | Returns combined Drizzle schema |
38
- | `getSettings()` | Method | Returns connection settings |
39
- | `getConnector()` | Method | Returns the Drizzle connector |
40
- | `configure()` | Method | Initializes the `connector` |
41
- | `getConnectionString()` | Method | Returns connection string |
42
- | `beginTransaction(opts?)` | Method | Starts a new database transaction |
53
+ | `getSchema()` | `Schema` | Returns combined Drizzle schema |
54
+ | `getSettings()` | `Settings` | Returns connection settings |
55
+ | `getConnector()` | `TNodePostgresConnector<Schema>` | Returns the Drizzle connector |
56
+ | `getConnectionString()` | `ValueOrPromise<string>` | Returns connection string |
57
+ | `configure(opts?)` | `ValueOrPromise<void>` | Initializes pool and connector |
58
+ | `beginTransaction(opts?)` | `Promise<ITransaction<Schema>>` | Starts a new database transaction |
43
59
 
44
60
  ## `AbstractDataSource` & `BaseDataSource`
45
61
 
@@ -47,22 +63,64 @@ Contract for all datasource classes in the framework.
47
63
 
48
64
  ### `AbstractDataSource`
49
65
 
50
- This is the top-level abstract class that implements the `IDataSource` interface. It initializes the `BaseHelper` for logging and sets up the basic properties.
66
+ Top-level abstract class that implements `IDataSource`. Extends `BaseHelper` for scoped logging. Declares the core properties and abstract methods.
67
+
68
+ ```typescript
69
+ abstract class AbstractDataSource<
70
+ Settings extends object = {},
71
+ Schema extends TAnyDataSourceSchema = TAnyDataSourceSchema,
72
+ ConfigurableOptions extends object = {},
73
+ > extends BaseHelper implements IDataSource<Settings, Schema, ConfigurableOptions>
74
+ ```
75
+
76
+ **Properties:**
77
+
78
+ | Property | Type | Visibility | Description |
79
+ |----------|------|------------|-------------|
80
+ | `name` | `string` | public | Datasource identifier |
81
+ | `settings` | `Settings` | public | Connection configuration |
82
+ | `connector` | `TNodePostgresConnector<Schema>` | public | Drizzle ORM instance |
83
+ | `schema` | `Schema` | public | Combined schema (tables + relations) |
84
+ | `pool` | `Pool` | protected | node-postgres connection pool |
85
+
86
+ **Abstract methods** (must be implemented by subclasses):
87
+
88
+ | Method | Return Type | Description |
89
+ |--------|-------------|-------------|
90
+ | `configure(opts?)` | `ValueOrPromise<void>` | Initialize pool and Drizzle connector |
91
+ | `getConnectionString()` | `ValueOrPromise<string>` | Return the database connection URL |
92
+ | `beginTransaction(opts?)` | `Promise<ITransaction<Schema>>` | Start a new transaction |
93
+
94
+ **Concrete methods:**
95
+
96
+ | Method | Return Type | Description |
97
+ |--------|-------------|-------------|
98
+ | `getSettings()` | `Settings` | Returns `this.settings` |
99
+ | `getConnector()` | `TNodePostgresConnector<Schema>` | Returns `this.connector` |
100
+ | `getSchema()` | `Schema` | Returns `this.schema` (throws if not initialized) |
51
101
 
52
102
  ### `BaseDataSource`
53
103
 
54
- This class extends `AbstractDataSource` and provides a constructor with **auto-discovery** support. When you create your own datasource, you extend `BaseDataSource`.
104
+ Extends `AbstractDataSource` with a constructor, **schema auto-discovery**, and a default `beginTransaction()` implementation.
105
+
106
+ ```typescript
107
+ abstract class BaseDataSource<
108
+ Settings extends object = {},
109
+ Schema extends TAnyDataSourceSchema = TAnyDataSourceSchema,
110
+ ConfigurableOptions extends object = {},
111
+ > extends AbstractDataSource<Settings, Schema, ConfigurableOptions>
112
+ ```
55
113
 
56
114
  #### Key Features
57
115
 
58
116
  | Feature | Description |
59
117
  |---------|-------------|
60
- | **Driver Auto-Read** | Driver is read from `@datasource` decorator - no need to pass in constructor |
61
118
  | **Schema Auto-Discovery** | Schema is automatically built from registered `@repository` decorators |
62
- | **Manual Override** | You can still manually provide schema in constructor for full control |
119
+ | **Manual Override** | You can manually provide schema in constructor for full control |
120
+ | **Built-in Transaction Support** | `beginTransaction()` implemented using the `pool` property |
63
121
 
64
122
  > [!TIP]
65
- > Set `metadata.autoDiscovery` to `false` in the `@datasource` decorator to disable automatic schema discovery. This is useful when you want to manually provide the schema.
123
+ > Set `autoDiscovery` to `false` in the `@datasource` decorator to disable automatic schema discovery. This is useful when you want to manually provide the schema.
66
124
 
67
125
  ### Constructor Options
68
126
 
@@ -70,7 +128,6 @@ This class extends `AbstractDataSource` and provides a constructor with **auto-d
70
128
  constructor(opts: {
71
129
  name: string; // DataSource name (usually class name)
72
130
  config: Settings; // Database connection settings
73
- driver?: TDataSourceDriver; // Optional - read from @datasource if not provided
74
131
  schema?: Schema; // Optional - auto-discovered if not provided
75
132
  })
76
133
  ```
@@ -89,16 +146,16 @@ When you use `@repository({ model: YourModel, dataSource: YourDataSource })`, th
89
146
 
90
147
  1. **Your DataSource's `constructor` is called**:
91
148
  - You call `super()` with `name` and `config`
92
- - Driver is automatically read from `@datasource` decorator
93
- - Schema is auto-discovered from `@repository` bindings (or manually provided)
149
+ - Schema is auto-discovered from `@repository` bindings (or manually provided via `schema`)
94
150
 
95
151
  2. **`Application.registerDataSources()` is called during startup**:
96
152
  - The application gets your `DataSource` instance from the DI container
97
153
  - It calls the `configure()` method on your instance
98
154
 
99
155
  3. **Your `configure()` method runs**:
100
- - This is where you instantiate the Drizzle ORM
101
- - Use `this.getSchema()` to get the auto-discovered schema and pass to Drizzle
156
+ - Call `this.getSchema()` to get the auto-discovered schema
157
+ - Create a `Pool` instance and assign it to `this.pool` (required for transaction support)
158
+ - Create the Drizzle connector with the pool and schema
102
159
 
103
160
  ### Example Implementations
104
161
 
@@ -108,12 +165,8 @@ Simplest approach - schema is auto-discovered from repositories:
108
165
 
109
166
  ```typescript
110
167
  // src/datasources/postgres.datasource.ts
111
- import {
112
- BaseDataSource,
113
- datasource,
114
- TNodePostgresConnector,
115
- ValueOrPromise,
116
- } from '@venizia/ignis';
168
+ import { BaseDataSource, datasource, ValueOrPromise } from '@venizia/ignis';
169
+ import { applicationEnvironment, int } from '@venizia/ignis-helpers';
117
170
  import { drizzle } from 'drizzle-orm/node-postgres';
118
171
  import { Pool } from 'pg';
119
172
 
@@ -123,6 +176,7 @@ interface IDSConfigs {
123
176
  database: string;
124
177
  user: string;
125
178
  password: string;
179
+ ssl: boolean;
126
180
  }
127
181
 
128
182
  /**
@@ -134,17 +188,19 @@ interface IDSConfigs {
134
188
  * 3. Drizzle is initialized with the auto-discovered schema
135
189
  */
136
190
  @datasource({ driver: 'node-postgres' })
137
- export class PostgresDataSource extends BaseDataSource<TNodePostgresConnector, IDSConfigs> {
191
+ export class PostgresDataSource extends BaseDataSource<IDSConfigs> {
192
+ private readonly protocol = 'postgresql';
193
+
138
194
  constructor() {
139
195
  super({
140
196
  name: PostgresDataSource.name,
141
- // Driver is read from @datasource decorator - no need to pass here!
142
197
  config: {
143
- host: process.env.APP_ENV_POSTGRES_HOST ?? 'localhost',
144
- port: +(process.env.APP_ENV_POSTGRES_PORT ?? 5432),
145
- database: process.env.APP_ENV_POSTGRES_DATABASE ?? 'mydb',
146
- user: process.env.APP_ENV_POSTGRES_USERNAME ?? 'postgres',
147
- password: process.env.APP_ENV_POSTGRES_PASSWORD ?? '',
198
+ host: applicationEnvironment.get<string>('APP_ENV_POSTGRES_HOST'),
199
+ port: int(applicationEnvironment.get<string>('APP_ENV_POSTGRES_PORT')),
200
+ database: applicationEnvironment.get<string>('APP_ENV_POSTGRES_DATABASE'),
201
+ user: applicationEnvironment.get<string>('APP_ENV_POSTGRES_USERNAME'),
202
+ password: applicationEnvironment.get<string>('APP_ENV_POSTGRES_PASSWORD'),
203
+ ssl: false,
148
204
  },
149
205
  // NO schema property - auto-discovered from @repository bindings!
150
206
  });
@@ -154,16 +210,21 @@ export class PostgresDataSource extends BaseDataSource<TNodePostgresConnector, I
154
210
  // getSchema() auto-discovers models from @repository bindings
155
211
  const schema = this.getSchema();
156
212
 
157
- // Log discovered schema for debugging
158
- const schemaKeys = Object.keys(schema);
213
+ const dsSchema = Object.keys(schema);
159
214
  this.logger.debug(
160
215
  '[configure] Auto-discovered schema | Schema + Relations (%s): %o',
161
- schemaKeys.length,
162
- schemaKeys,
216
+ dsSchema.length,
217
+ dsSchema,
163
218
  );
164
219
 
165
- const client = new Pool(this.settings);
166
- this.connector = drizzle({ client, schema });
220
+ // Store pool reference for transaction support
221
+ this.pool = new Pool(this.settings);
222
+ this.connector = drizzle({ client: this.pool, schema });
223
+ }
224
+
225
+ override getConnectionString(): ValueOrPromise<string> {
226
+ const { host, port, user, password, database } = this.settings;
227
+ return `${this.protocol}://${user}:${password}@${host}:${port}/${database}`;
167
228
  }
168
229
  }
169
230
  ```
@@ -191,7 +252,7 @@ import {
191
252
  } from '@/models/entities';
192
253
 
193
254
  @datasource({ driver: 'node-postgres' })
194
- export class PostgresDataSource extends BaseDataSource<TNodePostgresConnector, IDSConfigs> {
255
+ export class PostgresDataSource extends BaseDataSource<IDSConfigs> {
195
256
  constructor() {
196
257
  super({
197
258
  name: PostgresDataSource.name,
@@ -214,13 +275,20 @@ export class PostgresDataSource extends BaseDataSource<TNodePostgresConnector, I
214
275
 
215
276
  override configure(): ValueOrPromise<void> {
216
277
  // When schema is manually provided, getSchema() returns it directly
217
- const client = new Pool(this.settings);
218
- this.connector = drizzle({ client, schema: this.getSchema() });
278
+ this.pool = new Pool(this.settings);
279
+ this.connector = drizzle({ client: this.pool, schema: this.getSchema() });
280
+ }
281
+
282
+ override getConnectionString(): ValueOrPromise<string> {
283
+ // ...
219
284
  }
220
285
  }
221
286
  ```
222
287
 
223
- ### @datasource Decorator
288
+ > [!IMPORTANT]
289
+ > You must assign `this.pool` in your `configure()` method. The built-in `beginTransaction()` uses `this.pool` to acquire a `PoolClient` for transaction isolation. If `this.pool` is not set, `beginTransaction()` will throw an error.
290
+
291
+ ### `@datasource` Decorator
224
292
 
225
293
  The `@datasource` decorator registers datasource metadata:
226
294
 
@@ -233,65 +301,75 @@ The `@datasource` decorator registers datasource metadata:
233
301
 
234
302
  | Option | Type | Default | Description |
235
303
  |--------|------|---------|-------------|
236
- | `driver` | `TDataSourceDriver` | - | Database driver name |
304
+ | `driver` | `TDataSourceDriver` | - | Database driver name (currently only `'node-postgres'`) |
237
305
  | `autoDiscovery` | `boolean` | `true` | Enable/disable schema auto-discovery |
238
306
 
239
307
  ### Abstract Methods
240
308
 
241
- These methods must be implemented in your datasource class:
309
+ When extending `BaseDataSource`, these methods must be implemented:
242
310
 
243
311
  | Method | Return Type | Description |
244
312
  |--------|-------------|-------------|
245
- | `configure(opts?)` | `ValueOrPromise<void>` | Initialize the Drizzle ORM connector. Called during application startup. |
313
+ | `configure(opts?)` | `ValueOrPromise<void>` | Initialize pool and Drizzle connector. Must set `this.pool` and `this.connector`. |
246
314
  | `getConnectionString()` | `ValueOrPromise<string>` | Return the database connection string. |
247
315
 
248
- ### Optional Override Methods
316
+ ### Helper Methods
249
317
 
250
- These methods can be optionally overridden for connection lifecycle management:
318
+ | Method | Description |
319
+ |--------|-------------|
320
+ | `getSchema()` | Returns the schema (auto-discovers via `discoverSchema()` if not manually provided) |
321
+ | `getSettings()` | Returns connection settings |
322
+ | `getConnector()` | Returns the Drizzle connector |
323
+ | `hasDiscoverableModels()` | Returns `true` if there are models registered for this datasource via `@repository` |
251
324
 
252
- | Method | Return Type | Description |
253
- |--------|-------------|-------------|
254
- | `connect()` | `Promise<Connector \| undefined>` | Establish database connection. Useful for connection pooling. |
255
- | `disconnect()` | `Promise<void>` | Close database connection gracefully. |
325
+ ### Protected Methods
256
326
 
257
- ```typescript
258
- @datasource({ driver: 'node-postgres' })
259
- export class PostgresDataSource extends BaseDataSource<TNodePostgresConnector, IDSConfigs> {
260
- // ... constructor and configure() ...
327
+ | Method | Description |
328
+ |--------|-------------|
329
+ | `discoverSchema()` | Queries the `MetadataRegistry` for all `@repository` bindings targeting this datasource, then calls `registry.buildSchema()` to merge tables and relations into a single schema object. |
261
330
 
262
- override async connect(): Promise<TNodePostgresConnector | undefined> {
263
- await (this.connector.client as Pool).connect();
264
- return this.connector;
265
- }
331
+ ## Connector Types
266
332
 
267
- override async disconnect(): Promise<void> {
268
- await (this.connector.client as Pool).end();
269
- }
270
- }
271
- ```
333
+ **File:** `packages/core/src/base/datasources/common/types.ts`
272
334
 
273
- ### Helper Methods
335
+ | Type | Description |
336
+ |------|-------------|
337
+ | `TNodePostgresConnector<Schema>` | Drizzle connector using `NodePgClient` (Pool or PoolClient) |
338
+ | `TNodePostgresTransactionConnector<Schema>` | Drizzle connector using `PoolClient` specifically (for transaction isolation) |
339
+ | `TAnyConnector<Schema>` | Union of both connector types |
340
+ | `TAnyDataSourceSchema` | `Record<string, any>` — base type for all schema objects |
274
341
 
275
- | Method | Description |
276
- |--------|-------------|
277
- | `getSchema()` | Returns the schema (auto-discovers if not manually provided) |
278
- | `getSettings()` | Returns connection settings |
279
- | `getConnector()` | Returns the Drizzle connector |
280
- | `hasDiscoverableModels()` | Returns `true` if there are models registered for this datasource |
342
+ ### `DataSourceDrivers`
343
+
344
+ Static class for driver validation:
345
+
346
+ ```typescript
347
+ DataSourceDrivers.NODE_POSTGRES // 'node-postgres'
348
+ DataSourceDrivers.isValid('node-postgres') // true
349
+ ```
281
350
 
282
351
  ## Transaction Support
283
352
 
284
353
  DataSources provide built-in transaction management through the `beginTransaction()` method. This allows you to perform atomic operations across multiple repositories.
285
354
 
286
- ### Transaction Types
355
+ ### How It Works
287
356
 
288
- **File:** `packages/core/src/base/datasources/common/types.ts`
357
+ `BaseDataSource.beginTransaction()` does the following:
358
+
359
+ 1. Acquires a `PoolClient` from `this.pool`
360
+ 2. Executes `BEGIN TRANSACTION ISOLATION LEVEL <level>` on the client
361
+ 3. Creates a separate Drizzle connector scoped to that client
362
+ 4. Returns an `ITransaction` object with `commit()`, `rollback()`, and the scoped `connector`
363
+
364
+ When `commit()` or `rollback()` is called, the client is released back to the pool.
365
+
366
+ ### Transaction Types
289
367
 
290
368
  | Type | Description |
291
369
  |------|-------------|
292
370
  | `ITransaction<Schema>` | Transaction object with `commit()`, `rollback()`, and `connector` |
293
371
  | `ITransactionOptions` | Options for starting a transaction (e.g., `isolationLevel`) |
294
- | `TIsolationLevel` | Union type: `'READ UNCOMMITTED'` \| `'READ COMMITTED'` \| `'REPEATABLE READ'` \| `'SERIALIZABLE'` |
372
+ | `TIsolationLevel` | Union type: `'READ COMMITTED'` \| `'REPEATABLE READ'` \| `'SERIALIZABLE'` |
295
373
  | `IsolationLevels` | Static class with isolation level constants and validation |
296
374
 
297
375
  ### ITransaction Interface
@@ -299,7 +377,7 @@ DataSources provide built-in transaction management through the `beginTransactio
299
377
  ```typescript
300
378
  interface ITransaction<Schema> {
301
379
  connector: TNodePostgresTransactionConnector<Schema>;
302
- isActive: boolean;
380
+ isActive: boolean; // read-only getter, false after commit/rollback
303
381
  isolationLevel: TIsolationLevel;
304
382
 
305
383
  commit(): Promise<void>;
@@ -315,7 +393,6 @@ Use the `IsolationLevels` static class for type-safe isolation level constants:
315
393
  import { IsolationLevels } from '@venizia/ignis';
316
394
 
317
395
  // Available levels
318
- IsolationLevels.READ_UNCOMMITTED // Allows dirty reads (least strict)
319
396
  IsolationLevels.READ_COMMITTED // Default - prevents dirty reads
320
397
  IsolationLevels.REPEATABLE_READ // Consistent reads within transaction
321
398
  IsolationLevels.SERIALIZABLE // Strictest isolation
@@ -325,6 +402,9 @@ IsolationLevels.isValid('READ COMMITTED'); // true
325
402
  IsolationLevels.isValid('INVALID'); // false
326
403
  ```
327
404
 
405
+ > [!NOTE]
406
+ > The default isolation level is `READ COMMITTED` when no `isolationLevel` option is provided.
407
+
328
408
  ### Usage Example
329
409
 
330
410
  ```typescript