@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.
- package/dist/mcp-server/common/paths.d.ts +4 -2
- package/dist/mcp-server/common/paths.d.ts.map +1 -1
- package/dist/mcp-server/common/paths.js +8 -6
- package/dist/mcp-server/common/paths.js.map +1 -1
- package/dist/mcp-server/tools/docs/get-document-content.tool.d.ts +1 -1
- package/dist/mcp-server/tools/docs/get-document-content.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/docs/get-document-content.tool.js +7 -7
- package/dist/mcp-server/tools/docs/get-document-metadata.tool.js +3 -3
- package/dist/mcp-server/tools/docs/get-package-overview.tool.d.ts +1 -1
- package/dist/mcp-server/tools/docs/get-package-overview.tool.js +1 -1
- package/package.json +1 -1
- package/wiki/best-practices/api-usage-examples.md +9 -9
- package/wiki/best-practices/architectural-patterns.md +19 -3
- package/wiki/best-practices/architecture-decisions.md +6 -6
- package/wiki/best-practices/code-style-standards/advanced-patterns.md +1 -1
- package/wiki/best-practices/code-style-standards/control-flow.md +1 -1
- package/wiki/best-practices/code-style-standards/function-patterns.md +2 -2
- package/wiki/best-practices/code-style-standards/index.md +2 -2
- package/wiki/best-practices/code-style-standards/naming-conventions.md +1 -1
- package/wiki/best-practices/code-style-standards/route-definitions.md +4 -4
- package/wiki/best-practices/data-modeling.md +1 -1
- package/wiki/best-practices/deployment-strategies.md +1 -1
- package/wiki/best-practices/error-handling.md +2 -2
- package/wiki/best-practices/performance-optimization.md +3 -3
- package/wiki/best-practices/security-guidelines.md +2 -2
- package/wiki/best-practices/troubleshooting-tips.md +1 -1
- package/wiki/{references → extensions}/components/authentication/api.md +12 -20
- package/wiki/{references → extensions}/components/authentication/errors.md +1 -1
- package/wiki/{references → extensions}/components/authentication/index.md +5 -8
- package/wiki/{references → extensions}/components/authentication/usage.md +20 -36
- package/wiki/{references → extensions}/components/authorization/api.md +62 -13
- package/wiki/{references → extensions}/components/authorization/errors.md +12 -7
- package/wiki/{references → extensions}/components/authorization/index.md +93 -6
- package/wiki/{references → extensions}/components/authorization/usage.md +42 -4
- package/wiki/{references → extensions}/components/health-check.md +5 -4
- package/wiki/{references → extensions}/components/index.md +2 -0
- package/wiki/{references → extensions}/components/mail/index.md +1 -1
- package/wiki/{references → extensions}/components/request-tracker.md +1 -1
- package/wiki/{references → extensions}/components/socket-io/api.md +2 -2
- package/wiki/{references → extensions}/components/socket-io/errors.md +2 -0
- package/wiki/{references → extensions}/components/socket-io/index.md +24 -20
- package/wiki/{references → extensions}/components/socket-io/usage.md +2 -2
- package/wiki/{references → extensions}/components/static-asset/api.md +14 -15
- package/wiki/{references → extensions}/components/static-asset/errors.md +3 -1
- package/wiki/{references → extensions}/components/static-asset/index.md +158 -89
- package/wiki/{references → extensions}/components/static-asset/usage.md +8 -5
- package/wiki/{references → extensions}/components/swagger.md +3 -3
- package/wiki/{references → extensions}/components/template/index.md +4 -4
- package/wiki/{references → extensions}/components/template/setup-page.md +1 -1
- package/wiki/{references → extensions}/components/template/single-page.md +1 -1
- package/wiki/{references → extensions}/components/websocket/api.md +7 -6
- package/wiki/{references → extensions}/components/websocket/errors.md +17 -3
- package/wiki/{references → extensions}/components/websocket/index.md +17 -11
- package/wiki/{references → extensions}/components/websocket/usage.md +2 -2
- package/wiki/{references → extensions}/helpers/crypto/index.md +1 -1
- package/wiki/{references → extensions}/helpers/env/index.md +9 -5
- package/wiki/{references → extensions}/helpers/error/index.md +2 -7
- package/wiki/{references → extensions}/helpers/index.md +18 -6
- package/wiki/{references → extensions}/helpers/kafka/admin.md +33 -16
- package/wiki/extensions/helpers/kafka/consumer.md +384 -0
- package/wiki/extensions/helpers/kafka/examples.md +361 -0
- package/wiki/extensions/helpers/kafka/index.md +639 -0
- package/wiki/{references → extensions}/helpers/kafka/producer.md +100 -96
- package/wiki/extensions/helpers/kafka/schema-registry.md +214 -0
- package/wiki/{references → extensions}/helpers/logger/index.md +2 -2
- package/wiki/{references → extensions}/helpers/queue/index.md +400 -4
- package/wiki/{references → extensions}/helpers/storage/api.md +170 -10
- package/wiki/{references → extensions}/helpers/storage/index.md +44 -8
- package/wiki/{references → extensions}/helpers/template/index.md +1 -1
- package/wiki/{references → extensions}/helpers/testing/index.md +4 -4
- package/wiki/{references → extensions}/helpers/types/index.md +63 -16
- package/wiki/{references → extensions}/helpers/websocket/index.md +1 -1
- package/wiki/extensions/index.md +48 -0
- package/wiki/guides/core-concepts/application/bootstrapping.md +55 -37
- package/wiki/guides/core-concepts/application/index.md +95 -35
- package/wiki/guides/core-concepts/components-guide.md +23 -19
- package/wiki/guides/core-concepts/components.md +34 -10
- package/wiki/guides/core-concepts/dependency-injection.md +99 -34
- package/wiki/guides/core-concepts/grpc-controllers.md +295 -0
- package/wiki/guides/core-concepts/persistent/datasources.md +27 -8
- package/wiki/guides/core-concepts/persistent/models.md +43 -1
- package/wiki/guides/core-concepts/persistent/repositories.md +75 -8
- package/wiki/guides/core-concepts/persistent/transactions.md +38 -8
- package/wiki/guides/core-concepts/{controllers.md → rest-controllers.md} +30 -33
- package/wiki/guides/core-concepts/services.md +19 -5
- package/wiki/guides/get-started/5-minute-quickstart.md +6 -7
- package/wiki/guides/get-started/philosophy.md +1 -1
- package/wiki/guides/index.md +2 -2
- package/wiki/guides/reference/glossary.md +7 -7
- package/wiki/guides/reference/mcp-docs-server.md +1 -1
- package/wiki/guides/tutorials/building-a-crud-api.md +2 -2
- package/wiki/guides/tutorials/complete-installation.md +17 -14
- package/wiki/guides/tutorials/ecommerce-api.md +18 -18
- package/wiki/guides/tutorials/realtime-chat.md +8 -8
- package/wiki/guides/tutorials/testing.md +2 -2
- package/wiki/index.md +4 -3
- package/wiki/references/base/application.md +341 -21
- package/wiki/references/base/bootstrapping.md +43 -13
- package/wiki/references/base/components.md +259 -8
- package/wiki/references/base/controllers.md +556 -253
- package/wiki/references/base/datasources.md +159 -79
- package/wiki/references/base/dependency-injection.md +299 -48
- package/wiki/references/base/filter-system/application-usage.md +18 -2
- package/wiki/references/base/filter-system/array-operators.md +14 -6
- package/wiki/references/base/filter-system/comparison-operators.md +9 -3
- package/wiki/references/base/filter-system/default-filter.md +28 -3
- package/wiki/references/base/filter-system/fields-order-pagination.md +17 -13
- package/wiki/references/base/filter-system/index.md +169 -11
- package/wiki/references/base/filter-system/json-filtering.md +51 -18
- package/wiki/references/base/filter-system/list-operators.md +4 -3
- package/wiki/references/base/filter-system/logical-operators.md +7 -2
- package/wiki/references/base/filter-system/null-operators.md +50 -0
- package/wiki/references/base/filter-system/quick-reference.md +82 -243
- package/wiki/references/base/filter-system/range-operators.md +7 -1
- package/wiki/references/base/filter-system/tips.md +34 -7
- package/wiki/references/base/filter-system/use-cases.md +6 -5
- package/wiki/references/base/grpc-controllers.md +984 -0
- package/wiki/references/base/index.md +32 -24
- package/wiki/references/base/middleware.md +347 -0
- package/wiki/references/base/models.md +390 -46
- package/wiki/references/base/providers.md +14 -14
- package/wiki/references/base/repositories/advanced.md +84 -69
- package/wiki/references/base/repositories/index.md +447 -12
- package/wiki/references/base/repositories/mixins.md +103 -98
- package/wiki/references/base/repositories/relations.md +129 -45
- package/wiki/references/base/repositories/soft-deletable.md +104 -23
- package/wiki/references/base/services.md +94 -14
- package/wiki/references/index.md +12 -10
- package/wiki/references/quick-reference.md +98 -65
- package/wiki/references/utilities/crypto.md +21 -4
- package/wiki/references/utilities/date.md +25 -7
- package/wiki/references/utilities/index.md +26 -24
- package/wiki/references/utilities/jsx.md +54 -54
- package/wiki/references/utilities/module.md +8 -6
- package/wiki/references/utilities/parse.md +16 -9
- package/wiki/references/utilities/performance.md +22 -7
- package/wiki/references/utilities/promise.md +19 -16
- package/wiki/references/utilities/request.md +48 -26
- package/wiki/references/utilities/schema.md +69 -6
- package/wiki/references/utilities/statuses.md +131 -140
- package/wiki/references/helpers/kafka/consumer.md +0 -473
- package/wiki/references/helpers/kafka/examples.md +0 -234
- package/wiki/references/helpers/kafka/index.md +0 -482
- /package/wiki/{references → extensions}/components/mail/api.md +0 -0
- /package/wiki/{references → extensions}/components/mail/errors.md +0 -0
- /package/wiki/{references → extensions}/components/mail/usage.md +0 -0
- /package/wiki/{references → extensions}/components/template/api-page.md +0 -0
- /package/wiki/{references → extensions}/components/template/errors-page.md +0 -0
- /package/wiki/{references → extensions}/components/template/usage-page.md +0 -0
- /package/wiki/{references → extensions}/helpers/cron/index.md +0 -0
- /package/wiki/{references → extensions}/helpers/inversion/index.md +0 -0
- /package/wiki/{references → extensions}/helpers/network/api.md +0 -0
- /package/wiki/{references → extensions}/helpers/network/index.md +0 -0
- /package/wiki/{references → extensions}/helpers/redis/index.md +0 -0
- /package/wiki/{references → extensions}/helpers/socket-io/api.md +0 -0
- /package/wiki/{references → extensions}/helpers/socket-io/index.md +0 -0
- /package/wiki/{references → extensions}/helpers/template/single-page.md +0 -0
- /package/wiki/{references → extensions}/helpers/uid/index.md +0 -0
- /package/wiki/{references → extensions}/helpers/websocket/api.md +0 -0
- /package/wiki/{references → extensions}/helpers/worker-thread/index.md +0 -0
- /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,
|
|
20
|
-
| **ITransaction** | Transaction object | `connector`, `isActive`, `commit()`, `rollback()` |
|
|
21
|
-
| **IsolationLevels** | Isolation level constants | `
|
|
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` | `
|
|
35
|
-
| `connector` | `TNodePostgresConnector
|
|
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()` |
|
|
38
|
-
| `getSettings()` |
|
|
39
|
-
| `getConnector()` |
|
|
40
|
-
| `
|
|
41
|
-
| `
|
|
42
|
-
| `beginTransaction(opts?)` |
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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 `
|
|
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
|
-
-
|
|
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
|
-
-
|
|
101
|
-
-
|
|
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
|
-
|
|
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<
|
|
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:
|
|
144
|
-
port:
|
|
145
|
-
database:
|
|
146
|
-
user:
|
|
147
|
-
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
|
-
|
|
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
|
-
|
|
162
|
-
|
|
216
|
+
dsSchema.length,
|
|
217
|
+
dsSchema,
|
|
163
218
|
);
|
|
164
219
|
|
|
165
|
-
|
|
166
|
-
this.
|
|
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<
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
###
|
|
316
|
+
### Helper Methods
|
|
249
317
|
|
|
250
|
-
|
|
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
|
-
|
|
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
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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
|
-
|
|
263
|
-
await (this.connector.client as Pool).connect();
|
|
264
|
-
return this.connector;
|
|
265
|
-
}
|
|
331
|
+
## Connector Types
|
|
266
332
|
|
|
267
|
-
|
|
268
|
-
await (this.connector.client as Pool).end();
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
```
|
|
333
|
+
**File:** `packages/core/src/base/datasources/common/types.ts`
|
|
272
334
|
|
|
273
|
-
|
|
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
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
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
|
-
###
|
|
355
|
+
### How It Works
|
|
287
356
|
|
|
288
|
-
|
|
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
|
|
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
|