@breadstone/archipel-mcp 0.0.21 → 0.0.23
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/README.md +32 -13
- package/data/guides/ai-text-generation.md +16 -24
- package/data/guides/cryptography-and-otp.md +2 -2
- package/data/guides/database-setup.md +4 -3
- package/data/guides/email-templates.md +52 -42
- package/data/guides/getting-started.md +6 -6
- package/data/guides/resource-management.md +9 -9
- package/data/packages/platform-authentication/api/Interface.IMfaSubjectUpdate.md +1 -1
- package/data/packages/platform-authentication/api/index.md +1 -1
- package/data/packages/platform-blob-storage/api/Variable.AWS_S3_PROVIDER_OPTIONS.md +1 -1
- package/data/packages/platform-blob-storage/api/Variable.AZURE_BLOB_PROVIDER_OPTIONS.md +1 -1
- package/data/packages/platform-blob-storage/api/Variable.BLOB_PROVIDER.md +1 -1
- package/data/packages/platform-blob-storage/api/Variable.VERCEL_BLOB_PROVIDER_OPTIONS.md +1 -1
- package/data/packages/platform-caching/api/Class.RedisLayeredCache.md +3 -3
- package/data/packages/platform-core/api/Class.ErrorTemplateService.md +1 -1
- package/data/packages/platform-core/api/Class.HostService.md +1 -1
- package/data/packages/platform-core/api/Variable.ID_GENERATOR_TOKEN.md +1 -1
- package/data/packages/platform-core/api/index.md +0 -27
- package/data/packages/platform-core/index.md +7 -4
- package/data/packages/platform-cryptography/api/Class.BcryptService.md +4 -4
- package/data/packages/platform-cryptography/api/Class.OtpService.md +6 -6
- package/data/packages/platform-cryptography/api/Variable.BCRYPT_OPTIONS.md +2 -2
- package/data/packages/platform-cryptography/api/Variable.MAX_BCRYPT_PASSWORD_BYTES.md +1 -1
- package/data/packages/platform-cryptography/api/Variable.MIN_BCRYPT_ROUNDS.md +1 -1
- package/data/packages/platform-cryptography/api/Variable.OTP_OPTIONS.md +2 -2
- package/data/packages/platform-cryptography/api/Variable.OTP_SERVICE_TOKEN.md +2 -2
- package/data/packages/platform-cryptography/api/Variable.TOTP_EPOCH_TOLERANCE.md +1 -1
- package/data/packages/platform-cryptography/api/index.md +3 -3
- package/data/packages/platform-documents/api/Class.BaseDocumentRenderer.md +32 -1
- package/data/packages/platform-documents/api/Class.DocumentEngine.md +4 -4
- package/data/packages/platform-documents/api/Class.DocumentModule.md +2 -2
- package/data/packages/platform-documents/api/Class.DocxDocumentRenderer2.md +333 -0
- package/data/packages/platform-documents/api/Class.PdfDocumentRenderer.md +355 -0
- package/data/packages/platform-documents/api/Interface.IDocumentModuleOptions.md +31 -5
- package/data/packages/platform-documents/api/Variable.DOCUMENT_MODULE_OPTIONS.md +1 -1
- package/data/packages/platform-documents/api/Variable.DOCUMENT_PARSER_TOKEN.md +1 -1
- package/data/packages/platform-documents/api/Variable.DOCUMENT_RENDERER_TOKEN.md +1 -1
- package/data/packages/platform-documents/api/Variable.IMAGE_PROCESSOR_TOKEN.md +1 -1
- package/data/packages/platform-documents/api/index.md +2 -0
- package/data/packages/platform-esigning/api/Class.EsigningClientPort.md +1 -1
- package/data/packages/platform-health/index.md +128 -0
- package/data/packages/platform-mailing/api/Class.DeliveryStrategyBase.md +0 -1
- package/data/packages/platform-mailing/api/Class.MailModule.md +1 -1
- package/data/packages/platform-mailing/api/Class.MailVerificationService.md +1 -1
- package/data/packages/platform-mailing/api/Class.TemplateFetchStrategyBase.md +0 -5
- package/data/packages/platform-mailing/api/Variable.SMTP_CONFIG_ENTRIES.md +14 -0
- package/data/packages/platform-mailing/api/Variable.SMTP_HOST.md +14 -0
- package/data/packages/platform-mailing/api/Variable.SMTP_PASSWORD.md +14 -0
- package/data/packages/platform-mailing/api/Variable.SMTP_PORT.md +14 -0
- package/data/packages/platform-mailing/api/Variable.SMTP_SECURE.md +14 -0
- package/data/packages/platform-mailing/api/Variable.SMTP_USER.md +14 -0
- package/data/packages/platform-mailing/api/index.md +7 -4
- package/data/packages/platform-mapping/index.md +121 -0
- package/data/packages/platform-mcp/api/Variable.MCP_MODULE_OPTIONS.md +1 -1
- package/data/packages/platform-openapi/api/Class.SwaggerMultiDocumentService.md +4 -4
- package/data/packages/platform-resources/index.md +135 -0
- package/data/packages/platform-telemetry/api/Class.OtelSdkHolder.md +1 -1
- package/data/packages/platform-telemetry/api/Variable.TELEMETRY_ENABLED.md +1 -1
- package/data/packages/platform-telemetry/api/Variable.TELEMETRY_FACADE.md +1 -1
- package/data/packages/platform-telemetry/api/Variable.TELEMETRY_OPTIONS.md +1 -1
- package/{src/knowledge/configPattern.js → data/patterns/config-pattern.md} +46 -49
- package/{src/knowledge/dtoPattern.js → data/patterns/dto-pattern.md} +58 -61
- package/{src/knowledge/errorHandlingPattern.js → data/patterns/error-handling-pattern.md} +35 -38
- package/{src/knowledge/guardPattern.js → data/patterns/guard-pattern.md} +35 -38
- package/{src/knowledge/mappingPattern.js → data/patterns/mapping-pattern.md} +43 -144
- package/data/patterns/module-pattern.md +182 -0
- package/data/patterns/query-pattern.md +137 -0
- package/data/patterns/repository-pattern.md +208 -0
- package/{src/knowledge/testingPattern.js → data/patterns/testing-pattern.md} +37 -40
- package/package.json +2 -2
- package/src/PatternsLoader.d.ts +12 -0
- package/src/PatternsLoader.js +65 -0
- package/src/generators/mappingPatternGenerator.d.ts +5 -0
- package/src/generators/mappingPatternGenerator.js +107 -0
- package/src/generators/modulePatternGenerator.d.ts +5 -0
- package/src/generators/modulePatternGenerator.js +107 -0
- package/src/generators/queryPatternGenerator.d.ts +4 -0
- package/src/generators/queryPatternGenerator.js +83 -0
- package/src/generators/repositoryPatternGenerator.d.ts +5 -0
- package/src/generators/repositoryPatternGenerator.js +165 -0
- package/src/main.js +15 -9
- package/src/models/IPatternDoc.d.ts +15 -0
- package/src/models/IPatternDoc.js +3 -0
- package/src/tools/registerGetConfigPatternTool.d.ts +2 -1
- package/src/tools/registerGetConfigPatternTool.js +5 -4
- package/src/tools/registerGetDtoPatternTool.d.ts +2 -1
- package/src/tools/registerGetDtoPatternTool.js +5 -4
- package/src/tools/registerGetErrorHandlingPatternTool.d.ts +2 -1
- package/src/tools/registerGetErrorHandlingPatternTool.js +5 -4
- package/src/tools/registerGetGuardPatternTool.d.ts +2 -1
- package/src/tools/registerGetGuardPatternTool.js +5 -4
- package/src/tools/registerGetMappingPatternTool.d.ts +2 -1
- package/src/tools/registerGetMappingPatternTool.js +6 -5
- package/src/tools/registerGetModulePatternTool.d.ts +2 -1
- package/src/tools/registerGetModulePatternTool.js +6 -5
- package/src/tools/registerGetQueryPatternTool.d.ts +2 -1
- package/src/tools/registerGetQueryPatternTool.js +6 -5
- package/src/tools/registerGetRepositoryPatternTool.d.ts +2 -1
- package/src/tools/registerGetRepositoryPatternTool.js +6 -5
- package/src/tools/registerGetTestingPatternTool.d.ts +2 -1
- package/src/tools/registerGetTestingPatternTool.js +5 -4
- package/data/packages/platform-core/api/Class.BlobResourceStrategy.md +0 -195
- package/data/packages/platform-core/api/Class.EmbeddedResourceStrategy.md +0 -215
- package/data/packages/platform-core/api/Class.FileResourceStrategy.md +0 -192
- package/data/packages/platform-core/api/Class.HealthModule.md +0 -42
- package/data/packages/platform-core/api/Class.HealthOrchestrator.md +0 -64
- package/data/packages/platform-core/api/Class.MappingBuilder.md +0 -110
- package/data/packages/platform-core/api/Class.MappingModule.md +0 -46
- package/data/packages/platform-core/api/Class.MappingNotRegisteredError.md +0 -56
- package/data/packages/platform-core/api/Class.MappingProfileBase.md +0 -52
- package/data/packages/platform-core/api/Class.MappingService.md +0 -284
- package/data/packages/platform-core/api/Class.ResourceManager.md +0 -565
- package/data/packages/platform-core/api/Class.ResourceModule.md +0 -46
- package/data/packages/platform-core/api/Class.TypeMappingNotRegisteredError.md +0 -57
- package/data/packages/platform-core/api/Function.createMappingKey.md +0 -39
- package/data/packages/platform-core/api/Interface.IBlobResourceStrategyConfig.md +0 -28
- package/data/packages/platform-core/api/Interface.IBlobServiceAdapter.md +0 -40
- package/data/packages/platform-core/api/Interface.IFileResourceStrategyConfig.md +0 -72
- package/data/packages/platform-core/api/Interface.IHealthCheckResult.md +0 -46
- package/data/packages/platform-core/api/Interface.IHealthIndicator.md +0 -41
- package/data/packages/platform-core/api/Interface.IMappingBuilder.md +0 -76
- package/data/packages/platform-core/api/Interface.IMappingKey.md +0 -58
- package/data/packages/platform-core/api/Interface.IMappingProfile.md +0 -32
- package/data/packages/platform-core/api/Interface.IResourceManagerConfig.md +0 -89
- package/data/packages/platform-core/api/Interface.IResourceMetadata.md +0 -94
- package/data/packages/platform-core/api/Interface.IResourceResult.md +0 -34
- package/data/packages/platform-core/api/Interface.IResourceStrategy.md +0 -134
- package/data/packages/platform-core/api/Variable.HEALTH_INDICATORS_TOKEN.md +0 -14
- package/data/packages/platform-mailing/api/Class.BlobTemplateFetchStrategy.md +0 -60
- package/data/packages/platform-mailing/api/Class.FileTemplateFetchStrategy.md +0 -58
- package/data/packages/platform-mailing/api/Class.LogDeliveryStrategy.md +0 -71
- package/src/knowledge/configPattern.d.ts +0 -5
- package/src/knowledge/dtoPattern.d.ts +0 -5
- package/src/knowledge/errorHandlingPattern.d.ts +0 -5
- package/src/knowledge/guardPattern.d.ts +0 -5
- package/src/knowledge/mappingPattern.d.ts +0 -6
- package/src/knowledge/modulePattern.d.ts +0 -6
- package/src/knowledge/modulePattern.js +0 -283
- package/src/knowledge/queryPattern.d.ts +0 -6
- package/src/knowledge/queryPattern.js +0 -215
- package/src/knowledge/repositoryPattern.d.ts +0 -6
- package/src/knowledge/repositoryPattern.js +0 -367
- package/src/knowledge/testingPattern.d.ts +0 -5
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: platform-resources
|
|
3
|
+
description: Multi-strategy resource management with MIME type detection and optional caching.
|
|
4
|
+
order: 3
|
|
5
|
+
tags: [resources, files, blob, mime, caching]
|
|
6
|
+
package: '@breadstone/archipel-platform-resources'
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# platform-resources
|
|
10
|
+
|
|
11
|
+
Multi-strategy resource management for NestJS applications. Loads files from the file system, embedded buffers, or blob storage with MIME type detection and optional caching. Extracted from `platform-core` to provide a focused, independently versionable resource module.
|
|
12
|
+
|
|
13
|
+
**Package:** `@breadstone/archipel-platform-resources`
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import {
|
|
19
|
+
ResourceModule,
|
|
20
|
+
ResourceManager,
|
|
21
|
+
FileResourceStrategy,
|
|
22
|
+
BlobResourceStrategy,
|
|
23
|
+
EmbeddedResourceStrategy,
|
|
24
|
+
ResourceNotFoundError,
|
|
25
|
+
} from '@breadstone/archipel-platform-resources';
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Module Registration
|
|
31
|
+
|
|
32
|
+
Register the module with one or more resource strategies:
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { Module } from '@nestjs/common';
|
|
36
|
+
import { ResourceModule, FileResourceStrategy, EmbeddedResourceStrategy } from '@breadstone/archipel-platform-resources';
|
|
37
|
+
import { join } from 'node:path';
|
|
38
|
+
|
|
39
|
+
@Module({
|
|
40
|
+
imports: [
|
|
41
|
+
ResourceModule.forRoot({
|
|
42
|
+
strategies: [
|
|
43
|
+
new FileResourceStrategy({
|
|
44
|
+
basePath: join(__dirname, '..', 'assets'),
|
|
45
|
+
}),
|
|
46
|
+
new EmbeddedResourceStrategy([
|
|
47
|
+
{ name: 'fallback.html', buffer: Buffer.from('<html>Fallback</html>') },
|
|
48
|
+
]),
|
|
49
|
+
],
|
|
50
|
+
}),
|
|
51
|
+
],
|
|
52
|
+
})
|
|
53
|
+
export class AppModule {}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Using ResourceManager
|
|
57
|
+
|
|
58
|
+
Inject and use `ResourceManager` to load resources at runtime:
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
import { Injectable } from '@nestjs/common';
|
|
62
|
+
import { ResourceManager } from '@breadstone/archipel-platform-resources';
|
|
63
|
+
|
|
64
|
+
@Injectable()
|
|
65
|
+
export class TemplateService {
|
|
66
|
+
constructor(private readonly _resourceManager: ResourceManager) {}
|
|
67
|
+
|
|
68
|
+
public async loadTemplate(name: string): Promise<string> {
|
|
69
|
+
const result = await this._resourceManager.get(name);
|
|
70
|
+
return result.buffer.toString('utf-8');
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## Strategies
|
|
78
|
+
|
|
79
|
+
| Strategy | Description |
|
|
80
|
+
| --------------------------- | ----------------------------------------------------------------- |
|
|
81
|
+
| `FileResourceStrategy` | Loads resources from the local file system with glob support |
|
|
82
|
+
| `BlobResourceStrategy` | Loads resources from a blob storage adapter (Vercel, Azure, S3) |
|
|
83
|
+
| `EmbeddedResourceStrategy` | Serves pre-loaded in-memory buffers |
|
|
84
|
+
|
|
85
|
+
### BlobResourceStrategy
|
|
86
|
+
|
|
87
|
+
For loading resources from cloud blob storage, provide an adapter that implements `IBlobServiceAdapter`:
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
import { BlobResourceStrategy, type IBlobServiceAdapter } from '@breadstone/archipel-platform-resources';
|
|
91
|
+
|
|
92
|
+
const blobStrategy = new BlobResourceStrategy({
|
|
93
|
+
adapter: myBlobAdapter,
|
|
94
|
+
containerName: 'templates',
|
|
95
|
+
});
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Custom Strategies
|
|
99
|
+
|
|
100
|
+
Implement `IResourceStrategy` to create your own resource loading strategy:
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
import type { IResourceStrategy, IResourceResult } from '@breadstone/archipel-platform-resources';
|
|
104
|
+
|
|
105
|
+
export class CustomStrategy implements IResourceStrategy {
|
|
106
|
+
public async get(name: string): Promise<IResourceResult | undefined> {
|
|
107
|
+
// Custom loading logic
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## Interfaces
|
|
115
|
+
|
|
116
|
+
| Interface | Description |
|
|
117
|
+
| ---------------------- | ---------------------------------------- |
|
|
118
|
+
| `IResourceResult` | Result object with `buffer` and `metadata` |
|
|
119
|
+
| `IResourceMetadata` | Metadata including `mimeType` and `size` |
|
|
120
|
+
| `IResourceStrategy` | Strategy contract for resource loading |
|
|
121
|
+
| `IBlobServiceAdapter` | Adapter contract for blob storage access |
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## Error Classes
|
|
126
|
+
|
|
127
|
+
| Error | Description |
|
|
128
|
+
| ------------------------ | --------------------------------------------- |
|
|
129
|
+
| `ResourceNotFoundError` | Thrown when a requested resource is not found |
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## API Reference
|
|
134
|
+
|
|
135
|
+
The auto-generated API reference is published when API docs are generated for this package.
|
|
@@ -61,7 +61,7 @@ setSdk(sdk): void;
|
|
|
61
61
|
Defined in: [OtelSdkHolder.ts:30](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-telemetry/src/OtelSdkHolder.ts#L30)
|
|
62
62
|
|
|
63
63
|
Stores the SDK reference so it can be shut down later.
|
|
64
|
-
Can only be called once
|
|
64
|
+
Can only be called once - subsequent calls are ignored.
|
|
65
65
|
|
|
66
66
|
#### Parameters
|
|
67
67
|
|
|
@@ -9,4 +9,4 @@ editUrl: false
|
|
|
9
9
|
const TELEMETRY_ENABLED: typeof TELEMETRY_ENABLED;
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
-
Defined in: [tokens.ts:4](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-telemetry/src/tokens.ts#L4)
|
|
12
|
+
Defined in: [tokens/TelemetryTokens.ts:4](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-telemetry/src/tokens/TelemetryTokens.ts#L4)
|
|
@@ -9,4 +9,4 @@ editUrl: false
|
|
|
9
9
|
const TELEMETRY_FACADE: typeof TELEMETRY_FACADE;
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
-
Defined in: [tokens.ts:3](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-telemetry/src/tokens.ts#L3)
|
|
12
|
+
Defined in: [tokens/TelemetryTokens.ts:3](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-telemetry/src/tokens/TelemetryTokens.ts#L3)
|
|
@@ -9,4 +9,4 @@ editUrl: false
|
|
|
9
9
|
const TELEMETRY_OPTIONS: typeof TELEMETRY_OPTIONS;
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
-
Defined in: [tokens.ts:2](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-telemetry/src/tokens.ts#L2)
|
|
12
|
+
Defined in: [tokens/TelemetryTokens.ts:2](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-telemetry/src/tokens/TelemetryTokens.ts#L2)
|
|
@@ -1,46 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
exports.CONFIG_PATTERN_KNOWLEDGE = `# Archipel Configuration Pattern
|
|
1
|
+
---
|
|
2
|
+
title: Configuration Pattern
|
|
3
|
+
description: Typed config keys, ConfigRegistry, ConfigService, env.ts conventions, and ConfigModule integration.
|
|
4
|
+
order: 1
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Archipel Configuration Pattern
|
|
9
8
|
|
|
10
9
|
## Overview
|
|
11
10
|
|
|
12
11
|
Archipel uses a **typed configuration key** system with a **central registry**.
|
|
13
|
-
Each platform library declares its required and optional config keys in an
|
|
14
|
-
file, which are registered into the global
|
|
15
|
-
|
|
12
|
+
Each platform library declares its required and optional config keys in an `env.ts`
|
|
13
|
+
file, which are registered into the global `ConfigRegistry`. At runtime, the
|
|
14
|
+
`ConfigService` resolves values through a pluggable strategy (environment variables,
|
|
16
15
|
Azure App Configuration, etc.).
|
|
17
16
|
|
|
18
|
-
**Rule:** No direct
|
|
17
|
+
**Rule:** No direct `process.env` access outside of config strategy implementations.
|
|
19
18
|
|
|
20
19
|
## Core Types
|
|
21
20
|
|
|
22
|
-
### IConfigKey<TType
|
|
21
|
+
### `IConfigKey<TType>`
|
|
23
22
|
|
|
24
|
-
|
|
23
|
+
```typescript
|
|
25
24
|
export interface IConfigKey<TType = unknown> {
|
|
26
25
|
readonly _type?: TType; // Phantom type for compile-time safety
|
|
27
26
|
readonly key: string; // The actual config key string
|
|
28
27
|
}
|
|
29
|
-
|
|
28
|
+
```
|
|
30
29
|
|
|
31
|
-
### createConfigKey<TType
|
|
30
|
+
### `createConfigKey<TType>`
|
|
32
31
|
|
|
33
|
-
|
|
32
|
+
```typescript
|
|
34
33
|
import { createConfigKey } from '@breadstone/archipel-platform-core';
|
|
35
34
|
|
|
36
35
|
export const APP_URL = createConfigKey<string>('APP_URL');
|
|
37
36
|
export const APP_PORT = createConfigKey<number>('APP_PORT');
|
|
38
37
|
export const FEATURE_ENABLED = createConfigKey<boolean>('FEATURE_ENABLED');
|
|
39
|
-
|
|
38
|
+
```
|
|
40
39
|
|
|
41
40
|
## ConfigService API
|
|
42
41
|
|
|
43
|
-
|
|
42
|
+
```typescript
|
|
44
43
|
@Injectable()
|
|
45
44
|
export class ConfigService {
|
|
46
45
|
|
|
@@ -54,18 +53,18 @@ export class ConfigService {
|
|
|
54
53
|
public compare<T>(key: string, value: T): boolean;
|
|
55
54
|
|
|
56
55
|
}
|
|
57
|
-
|
|
56
|
+
```
|
|
58
57
|
|
|
59
58
|
**Auto-parsing:** String values are automatically converted:
|
|
60
|
-
-
|
|
61
|
-
- Numeric strings →
|
|
62
|
-
- Empty strings →
|
|
59
|
+
- `'true'` / `'false'` → `boolean`
|
|
60
|
+
- Numeric strings → `number`
|
|
61
|
+
- Empty strings → `null`
|
|
63
62
|
|
|
64
63
|
## ConfigRegistry
|
|
65
64
|
|
|
66
65
|
A static global registry that collects all declared config keys at module initialization.
|
|
67
66
|
|
|
68
|
-
|
|
67
|
+
```typescript
|
|
69
68
|
export class ConfigRegistry {
|
|
70
69
|
|
|
71
70
|
// Register keys for a module
|
|
@@ -78,11 +77,11 @@ export class ConfigRegistry {
|
|
|
78
77
|
public static getModules(): ReadonlyArray<string>;
|
|
79
78
|
|
|
80
79
|
}
|
|
81
|
-
|
|
80
|
+
```
|
|
82
81
|
|
|
83
82
|
### IConfigRegistryEntry
|
|
84
83
|
|
|
85
|
-
|
|
84
|
+
```typescript
|
|
86
85
|
export interface IConfigRegistryEntry<TType = unknown> {
|
|
87
86
|
readonly key: IConfigKey<TType>;
|
|
88
87
|
readonly module: string;
|
|
@@ -90,13 +89,13 @@ export interface IConfigRegistryEntry<TType = unknown> {
|
|
|
90
89
|
readonly defaultValue?: TType;
|
|
91
90
|
readonly description?: string;
|
|
92
91
|
}
|
|
93
|
-
|
|
92
|
+
```
|
|
94
93
|
|
|
95
94
|
## How to Add Configuration to a Library
|
|
96
95
|
|
|
97
96
|
### Step 1: Define typed config keys in env.ts
|
|
98
97
|
|
|
99
|
-
|
|
98
|
+
```typescript
|
|
100
99
|
// src/env.ts
|
|
101
100
|
import { createConfigKey } from '@breadstone/archipel-platform-core';
|
|
102
101
|
import { ConfigRegistry, IConfigRegistryEntry } from '@breadstone/archipel-platform-core';
|
|
@@ -118,25 +117,25 @@ export const PLATFORM_PAYMENTS_CONFIG_ENTRIES: ReadonlyArray<Omit<IConfigRegistr
|
|
|
118
117
|
{ key: STRIPE_WEBHOOK_SECRET, required: true, description: 'Stripe webhook signing secret.' },
|
|
119
118
|
{ key: PAYMENT_CURRENCY, required: false, defaultValue: 'EUR', description: 'Default payment currency.' },
|
|
120
119
|
];
|
|
121
|
-
|
|
120
|
+
```
|
|
122
121
|
|
|
123
122
|
### Step 2: Register in ConfigModule
|
|
124
123
|
|
|
125
|
-
|
|
124
|
+
```typescript
|
|
126
125
|
// In the module's register() method:
|
|
127
126
|
imports: [ConfigModule.register('platform-payments', PLATFORM_PAYMENTS_CONFIG_ENTRIES)]
|
|
128
|
-
|
|
127
|
+
```
|
|
129
128
|
|
|
130
129
|
Or for libraries without a dedicated module (self-registration):
|
|
131
130
|
|
|
132
|
-
|
|
131
|
+
```typescript
|
|
133
132
|
// At the bottom of env.ts:
|
|
134
133
|
ConfigRegistry.register('platform-payments', PLATFORM_PAYMENTS_CONFIG_ENTRIES);
|
|
135
|
-
|
|
134
|
+
```
|
|
136
135
|
|
|
137
136
|
### Step 3: Use in services
|
|
138
137
|
|
|
139
|
-
|
|
138
|
+
```typescript
|
|
140
139
|
@Injectable()
|
|
141
140
|
export class StripeClient {
|
|
142
141
|
|
|
@@ -151,41 +150,41 @@ export class StripeClient {
|
|
|
151
150
|
}
|
|
152
151
|
|
|
153
152
|
}
|
|
154
|
-
|
|
153
|
+
```
|
|
155
154
|
|
|
156
155
|
## ConfigModule
|
|
157
156
|
|
|
158
157
|
### register() — Per-library config registration
|
|
159
158
|
|
|
160
|
-
Declares which config keys a library needs. Used in
|
|
159
|
+
Declares which config keys a library needs. Used in `imports` of feature modules.
|
|
161
160
|
|
|
162
|
-
|
|
161
|
+
```typescript
|
|
163
162
|
ConfigModule.register('platform-authentication', PLATFORM_AUTHENTICATION_CONFIG_ENTRIES)
|
|
164
|
-
|
|
163
|
+
```
|
|
165
164
|
|
|
166
165
|
### forRoot() — Application bootstrap
|
|
167
166
|
|
|
168
167
|
Configures the global strategy and static overrides. Used once in the root module.
|
|
169
168
|
|
|
170
|
-
|
|
169
|
+
```typescript
|
|
171
170
|
ConfigModule.forRoot({
|
|
172
171
|
strategyFactory: () => new EnvironmentConfigStrategy(),
|
|
173
172
|
statics: { APP_VERSION: '1.0.0' },
|
|
174
173
|
})
|
|
175
|
-
|
|
174
|
+
```
|
|
176
175
|
|
|
177
176
|
## ConfigStrategyBase
|
|
178
177
|
|
|
179
178
|
Pluggable strategy for resolving config values:
|
|
180
179
|
|
|
181
|
-
|
|
180
|
+
```typescript
|
|
182
181
|
export abstract class ConfigStrategyBase {
|
|
183
182
|
public abstract initialize(): void;
|
|
184
183
|
public abstract resolve<T>(key: string): T;
|
|
185
184
|
public abstract tryResolve<T>(key: string, fallback: T): T;
|
|
186
185
|
public abstract has(key: string): boolean;
|
|
187
186
|
}
|
|
188
|
-
|
|
187
|
+
```
|
|
189
188
|
|
|
190
189
|
Implementations can read from environment variables, Azure App Configuration, Consul, etc.
|
|
191
190
|
|
|
@@ -200,12 +199,10 @@ Implementations can read from environment variables, Azure App Configuration, Co
|
|
|
200
199
|
|
|
201
200
|
## Rules
|
|
202
201
|
|
|
203
|
-
1. **All config keys defined via
|
|
204
|
-
2. **Each library declares entries in
|
|
205
|
-
3. **Registration via
|
|
206
|
-
4.
|
|
207
|
-
5. **Use
|
|
202
|
+
1. **All config keys defined via `createConfigKey<T>()`** — never raw `process.env` access.
|
|
203
|
+
2. **Each library declares entries in `env.ts`** with required flag, default value, and description.
|
|
204
|
+
3. **Registration via `ConfigModule.register()`** in the module, or self-registration for libraries without modules.
|
|
205
|
+
4. **`ConfigService.get()` throws on missing required keys** — fail-fast at startup.
|
|
206
|
+
5. **Use `tryGet()` with fallback** for optional keys.
|
|
208
207
|
6. **Config key names use UPPER_SNAKE_CASE** matching environment variable conventions.
|
|
209
208
|
7. **Group related keys** with comment separators in env.ts.
|
|
210
|
-
`;
|
|
211
|
-
//# sourceMappingURL=configPattern.js.map
|
|
@@ -1,24 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
exports.DTO_PATTERN_KNOWLEDGE = `# Archipel DTO & Validation Pattern
|
|
1
|
+
---
|
|
2
|
+
title: DTO & Validation Pattern
|
|
3
|
+
description: Request/Response DTOs, class-validator decorators, cross-field validation, query parameter DTOs, OpenAPI integration, and naming conventions.
|
|
4
|
+
order: 2
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Archipel DTO & Validation Pattern
|
|
9
8
|
|
|
10
9
|
## Overview
|
|
11
10
|
|
|
12
11
|
Archipel uses **class-based DTOs** with **class-validator** decorators for input validation
|
|
13
|
-
and **class-transformer** decorators for serialization control. A global
|
|
12
|
+
and **class-transformer** decorators for serialization control. A global `ValidationPipe`
|
|
14
13
|
enforces validation on all incoming requests automatically.
|
|
15
14
|
|
|
16
15
|
Request DTOs validate input; Response classes define the output shape with
|
|
17
|
-
|
|
16
|
+
`@ApiProperty` decorators for OpenAPI documentation.
|
|
18
17
|
|
|
19
18
|
## Global Validation Pipe
|
|
20
19
|
|
|
21
|
-
|
|
20
|
+
```typescript
|
|
22
21
|
// In main.ts bootstrap:
|
|
23
22
|
app.useGlobalPipes(
|
|
24
23
|
new ValidationPipe({
|
|
@@ -27,11 +26,11 @@ app.useGlobalPipes(
|
|
|
27
26
|
transform: true, // Auto-transform payloads to DTO instances
|
|
28
27
|
}),
|
|
29
28
|
);
|
|
30
|
-
|
|
29
|
+
```
|
|
31
30
|
|
|
32
31
|
## Request DTO (Input Validation)
|
|
33
32
|
|
|
34
|
-
|
|
33
|
+
```typescript
|
|
35
34
|
// dtos/CreateUserRequest.ts
|
|
36
35
|
import { Expose } from 'class-transformer';
|
|
37
36
|
import { IsEmail, IsString, MinLength, MaxLength } from 'class-validator';
|
|
@@ -58,11 +57,11 @@ export class CreateUserRequest {
|
|
|
58
57
|
public password!: string;
|
|
59
58
|
|
|
60
59
|
}
|
|
61
|
-
|
|
60
|
+
```
|
|
62
61
|
|
|
63
62
|
## Response DTO (Output Shape)
|
|
64
63
|
|
|
65
|
-
|
|
64
|
+
```typescript
|
|
66
65
|
// dtos/UserResponse.ts
|
|
67
66
|
import { Expose } from 'class-transformer';
|
|
68
67
|
import { ApiProperty } from '@nestjs/swagger';
|
|
@@ -88,7 +87,7 @@ export class UserResponse {
|
|
|
88
87
|
// Note: password is intentionally NOT exposed
|
|
89
88
|
|
|
90
89
|
}
|
|
91
|
-
|
|
90
|
+
```
|
|
92
91
|
|
|
93
92
|
## Common Validators
|
|
94
93
|
|
|
@@ -96,48 +95,48 @@ export class UserResponse {
|
|
|
96
95
|
|
|
97
96
|
| Decorator | Purpose |
|
|
98
97
|
|-----------|---------|
|
|
99
|
-
|
|
|
100
|
-
|
|
|
101
|
-
|
|
|
102
|
-
|
|
|
103
|
-
|
|
|
104
|
-
|
|
|
105
|
-
|
|
|
106
|
-
|
|
|
98
|
+
| `@IsString()` | Must be a string |
|
|
99
|
+
| `@IsNumber()` | Must be a number |
|
|
100
|
+
| `@IsBoolean()` | Must be a boolean |
|
|
101
|
+
| `@IsEmail()` | Must be a valid email |
|
|
102
|
+
| `@IsUUID()` | Must be a valid UUID |
|
|
103
|
+
| `@IsDate()` | Must be a Date instance |
|
|
104
|
+
| `@IsEnum(MyEnum)` | Must be a value from the enum |
|
|
105
|
+
| `@IsOptional()` | Field is optional (skip validation if undefined) |
|
|
107
106
|
|
|
108
107
|
### String Constraints
|
|
109
108
|
|
|
110
109
|
| Decorator | Purpose |
|
|
111
110
|
|-----------|---------|
|
|
112
|
-
|
|
|
113
|
-
|
|
|
114
|
-
|
|
|
115
|
-
|
|
|
111
|
+
| `@MinLength(n)` | Minimum string length |
|
|
112
|
+
| `@MaxLength(n)` | Maximum string length |
|
|
113
|
+
| `@Matches(regex)` | Must match a regex pattern |
|
|
114
|
+
| `@IsNotEmpty()` | Must not be empty string |
|
|
116
115
|
|
|
117
116
|
### Number Constraints
|
|
118
117
|
|
|
119
118
|
| Decorator | Purpose |
|
|
120
119
|
|-----------|---------|
|
|
121
|
-
|
|
|
122
|
-
|
|
|
123
|
-
|
|
|
124
|
-
|
|
|
120
|
+
| `@Min(n)` | Minimum value |
|
|
121
|
+
| `@Max(n)` | Maximum value |
|
|
122
|
+
| `@IsPositive()` | Must be > 0 |
|
|
123
|
+
| `@IsInt()` | Must be integer |
|
|
125
124
|
|
|
126
125
|
### Nested & Array
|
|
127
126
|
|
|
128
127
|
| Decorator | Purpose |
|
|
129
128
|
|-----------|---------|
|
|
130
|
-
|
|
|
131
|
-
|
|
|
132
|
-
|
|
|
133
|
-
|
|
|
134
|
-
|
|
|
129
|
+
| `@ValidateNested()` | Validate nested objects |
|
|
130
|
+
| `@Type(() => Cls)` | Transform to class instance (class-transformer) |
|
|
131
|
+
| `@IsArray()` | Must be an array |
|
|
132
|
+
| `@ArrayMinSize(n)` | Minimum array length |
|
|
133
|
+
| `@ArrayMaxSize(n)` | Maximum array length |
|
|
135
134
|
|
|
136
135
|
## Cross-Field Validation
|
|
137
136
|
|
|
138
137
|
For fields that depend on each other, use custom class-level validators:
|
|
139
138
|
|
|
140
|
-
|
|
139
|
+
```typescript
|
|
141
140
|
import { ValidatorConstraint, ValidatorConstraintInterface, ValidationArguments, Validate } from 'class-validator';
|
|
142
141
|
|
|
143
142
|
@ValidatorConstraint({ name: 'Match', async: false })
|
|
@@ -153,7 +152,7 @@ export class MatchConstraint implements ValidatorConstraintInterface {
|
|
|
153
152
|
public defaultMessage(args: ValidationArguments): string {
|
|
154
153
|
const [relatedPropertyName] = args.constraints;
|
|
155
154
|
|
|
156
|
-
return
|
|
155
|
+
return `${args.property} must match ${relatedPropertyName}`;
|
|
157
156
|
}
|
|
158
157
|
|
|
159
158
|
}
|
|
@@ -172,13 +171,13 @@ export class ResetPasswordRequest {
|
|
|
172
171
|
public confirmPassword!: string;
|
|
173
172
|
|
|
174
173
|
}
|
|
175
|
-
|
|
174
|
+
```
|
|
176
175
|
|
|
177
176
|
## Query Parameter DTOs
|
|
178
177
|
|
|
179
|
-
For GET request query parameters, use
|
|
178
|
+
For GET request query parameters, use `@Transform()` and `@Type()` for type coercion:
|
|
180
179
|
|
|
181
|
-
|
|
180
|
+
```typescript
|
|
182
181
|
import { Type } from 'class-transformer';
|
|
183
182
|
import { IsOptional, IsInt, Min, Max, IsString } from 'class-validator';
|
|
184
183
|
import { ApiPropertyOptional } from '@nestjs/swagger';
|
|
@@ -206,13 +205,13 @@ export class PaginationQuery {
|
|
|
206
205
|
public search?: string;
|
|
207
206
|
|
|
208
207
|
}
|
|
209
|
-
|
|
208
|
+
```
|
|
210
209
|
|
|
211
210
|
## OpenAPI / Swagger Integration
|
|
212
211
|
|
|
213
212
|
### @ApiProperty Decorators
|
|
214
213
|
|
|
215
|
-
|
|
214
|
+
```typescript
|
|
216
215
|
@ApiProperty({
|
|
217
216
|
description: 'User email address',
|
|
218
217
|
example: 'user@example.com',
|
|
@@ -225,11 +224,11 @@ public email!: string;
|
|
|
225
224
|
maxLength: 500,
|
|
226
225
|
})
|
|
227
226
|
public bio?: string;
|
|
228
|
-
|
|
227
|
+
```
|
|
229
228
|
|
|
230
229
|
### Controller Response Decorators
|
|
231
230
|
|
|
232
|
-
|
|
231
|
+
```typescript
|
|
233
232
|
@Controller('/users')
|
|
234
233
|
@ApiTags('Users')
|
|
235
234
|
export class UsersController {
|
|
@@ -244,23 +243,23 @@ export class UsersController {
|
|
|
244
243
|
}
|
|
245
244
|
|
|
246
245
|
}
|
|
247
|
-
|
|
246
|
+
```
|
|
248
247
|
|
|
249
248
|
## Naming Conventions
|
|
250
249
|
|
|
251
250
|
| Type | Naming Pattern | Example |
|
|
252
251
|
|------|---------------|---------|
|
|
253
|
-
| Create input |
|
|
254
|
-
| Update input |
|
|
255
|
-
| Query params |
|
|
256
|
-
| Response |
|
|
257
|
-
| List response |
|
|
252
|
+
| Create input | `Create{Entity}Request` | `CreateUserRequest` |
|
|
253
|
+
| Update input | `Update{Entity}Request` | `UpdateUserRequest` |
|
|
254
|
+
| Query params | `{Entity}Query` or `Pagination{Entity}Query` | `UserQuery` |
|
|
255
|
+
| Response | `{Entity}Response` | `UserResponse` |
|
|
256
|
+
| List response | `{Entity}ListResponse` | `UserListResponse` |
|
|
258
257
|
|
|
259
258
|
## Constants for Bounds
|
|
260
259
|
|
|
261
260
|
Define and reuse constants for upper limits:
|
|
262
261
|
|
|
263
|
-
|
|
262
|
+
```typescript
|
|
264
263
|
// constants/ValidationConstants.ts
|
|
265
264
|
export const MAX_PAGE_SIZE = 100;
|
|
266
265
|
export const MAX_SEARCH_LIMIT = 50;
|
|
@@ -270,17 +269,15 @@ export const MAX_BIO_LENGTH = 500;
|
|
|
270
269
|
// In DTO:
|
|
271
270
|
@Max(MAX_PAGE_SIZE)
|
|
272
271
|
public perPage?: number;
|
|
273
|
-
|
|
272
|
+
```
|
|
274
273
|
|
|
275
274
|
## Rules
|
|
276
275
|
|
|
277
|
-
1. **Every field has
|
|
278
|
-
2. **Every field has
|
|
276
|
+
1. **Every field has `@Expose()`** for serialization control.
|
|
277
|
+
2. **Every field has `@ApiProperty()`** for OpenAPI documentation.
|
|
279
278
|
3. **Request DTOs use class-validator decorators** — validation is automatic via global pipe.
|
|
280
279
|
4. **Response DTOs have no validation decorators** — they're output-only shapes.
|
|
281
280
|
5. **Cross-field validation uses custom class-level validators** — never imperative checks in services.
|
|
282
|
-
6. **Query parameters use
|
|
283
|
-
7. **Upper bounds (
|
|
284
|
-
8.
|
|
285
|
-
`;
|
|
286
|
-
//# sourceMappingURL=dtoPattern.js.map
|
|
281
|
+
6. **Query parameters use `@Type(() => Number)`** for type coercion from strings.
|
|
282
|
+
7. **Upper bounds (`@Max`, `@MaxLength`) defined as exported constants** — never inline magic numbers.
|
|
283
|
+
8. **`whitelist: true` + `forbidNonWhitelisted: true`** strips and rejects unknown properties.
|