@defai.digital/config-domain 13.0.3
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/LICENSE +214 -0
- package/dist/aggregate.d.ts +110 -0
- package/dist/aggregate.d.ts.map +1 -0
- package/dist/aggregate.js +297 -0
- package/dist/aggregate.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/migrator.d.ts +93 -0
- package/dist/migrator.d.ts.map +1 -0
- package/dist/migrator.js +263 -0
- package/dist/migrator.js.map +1 -0
- package/dist/operations.d.ts +47 -0
- package/dist/operations.d.ts.map +1 -0
- package/dist/operations.js +260 -0
- package/dist/operations.js.map +1 -0
- package/dist/ports/detection.d.ts +61 -0
- package/dist/ports/detection.d.ts.map +1 -0
- package/dist/ports/detection.js +60 -0
- package/dist/ports/detection.js.map +1 -0
- package/dist/repository.d.ts +100 -0
- package/dist/repository.d.ts.map +1 -0
- package/dist/repository.js +135 -0
- package/dist/repository.js.map +1 -0
- package/dist/resolver.d.ts +92 -0
- package/dist/resolver.d.ts.map +1 -0
- package/dist/resolver.js +94 -0
- package/dist/resolver.js.map +1 -0
- package/dist/store.d.ts +85 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +247 -0
- package/dist/store.js.map +1 -0
- package/package.json +41 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @defai.digital/config-domain
|
|
3
|
+
*
|
|
4
|
+
* Configuration domain - config management following contract invariants.
|
|
5
|
+
*/
|
|
6
|
+
// Config Store
|
|
7
|
+
export { CONFIG_PATHS, DATA_PATHS, CONFIG_SUBDIRS, expandPath, getConfigPath, createConfigStore, initConfigDirectory, isSetupComplete, } from './store.js';
|
|
8
|
+
// Config Operations
|
|
9
|
+
export { parsePath, getValue, setValue, removeValue, mergeConfigs, diffConfigs, hasPath, getAllPaths, } from './operations.js';
|
|
10
|
+
// Config Aggregate
|
|
11
|
+
export { ConfigAggregate, createConfigAggregate, createAggregateFromConfig, } from './aggregate.js';
|
|
12
|
+
// Config Repository
|
|
13
|
+
export { InMemoryConfigEventStore, createConfigRepository, getConfigRepository, setConfigRepository, resetConfigRepository, } from './repository.js';
|
|
14
|
+
// Config Migrator
|
|
15
|
+
export { CURRENT_VERSION, MIN_SUPPORTED_VERSION, VERSION_ORDER, MIGRATIONS, getConfigVersion, compareVersions, isVersionSupported, getMigrationPath, needsMigration, migrateConfig, safeMigrateConfig, getMigrationInfo, } from './migrator.js';
|
|
16
|
+
// Detection Port
|
|
17
|
+
export { nullDetectionAdapter, setDetectionAdapter, getDetectionAdapter, resetDetectionAdapter, } from './ports/detection.js';
|
|
18
|
+
// Config Resolver (Multi-Level)
|
|
19
|
+
export { ConfigResolver, createConfigResolver, resolveConfig, resolveConfigFull, } from './resolver.js';
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,eAAe;AACf,OAAO,EACL,YAAY,EACZ,UAAU,EACV,cAAc,EAEd,UAAU,EACV,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,GAChB,MAAM,YAAY,CAAC;AAEpB,oBAAoB;AACpB,OAAO,EACL,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,WAAW,EACX,OAAO,EACP,WAAW,GACZ,MAAM,iBAAiB,CAAC;AAEzB,mBAAmB;AACnB,OAAO,EAEL,eAAe,EACf,qBAAqB,EACrB,yBAAyB,GAC1B,MAAM,gBAAgB,CAAC;AAExB,oBAAoB;AACpB,OAAO,EAIL,wBAAwB,EACxB,sBAAsB,EACtB,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,iBAAiB,CAAC;AAEzB,kBAAkB;AAClB,OAAO,EAGL,eAAe,EACf,qBAAqB,EACrB,aAAa,EACb,UAAU,EACV,gBAAgB,EAChB,eAAe,EACf,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,eAAe,CAAC;AAEvB,iBAAiB;AACjB,OAAO,EAGL,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,sBAAsB,CAAC;AAE9B,gCAAgC;AAChC,OAAO,EAGL,cAAc,EACd,oBAAoB,EACpB,aAAa,EACb,iBAAiB,GAClB,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config Version Migration
|
|
3
|
+
*
|
|
4
|
+
* Handles schema migrations for configuration files across versions.
|
|
5
|
+
*
|
|
6
|
+
* Invariants:
|
|
7
|
+
* - INV-CFG-MIG-001: Migrations are idempotent
|
|
8
|
+
* - INV-CFG-MIG-002: Version order is strictly increasing
|
|
9
|
+
* - INV-CFG-MIG-003: Unknown versions fail fast
|
|
10
|
+
*/
|
|
11
|
+
import { type AutomatosXConfig, ConfigError } from '@defai.digital/contracts';
|
|
12
|
+
/**
|
|
13
|
+
* Migration function signature
|
|
14
|
+
* Takes a config of any shape and returns a transformed config
|
|
15
|
+
*/
|
|
16
|
+
export type ConfigMigration = (config: unknown) => unknown;
|
|
17
|
+
/**
|
|
18
|
+
* Migration metadata
|
|
19
|
+
*/
|
|
20
|
+
export interface MigrationInfo {
|
|
21
|
+
/** Source version this migration applies to */
|
|
22
|
+
fromVersion: string;
|
|
23
|
+
/** Target version after migration */
|
|
24
|
+
toVersion: string;
|
|
25
|
+
/** Description of changes */
|
|
26
|
+
description: string;
|
|
27
|
+
/** Migration function */
|
|
28
|
+
migrate: ConfigMigration;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Current config schema version
|
|
32
|
+
*/
|
|
33
|
+
export declare const CURRENT_VERSION = "1.0.0";
|
|
34
|
+
/**
|
|
35
|
+
* Minimum supported version (older versions cannot be migrated)
|
|
36
|
+
*/
|
|
37
|
+
export declare const MIN_SUPPORTED_VERSION = "0.9.0";
|
|
38
|
+
/**
|
|
39
|
+
* Version order for migration path calculation
|
|
40
|
+
*/
|
|
41
|
+
export declare const VERSION_ORDER: readonly string[];
|
|
42
|
+
/**
|
|
43
|
+
* Registered migrations by source version
|
|
44
|
+
* Each migration transforms config from fromVersion to toVersion
|
|
45
|
+
*/
|
|
46
|
+
export declare const MIGRATIONS: Record<string, MigrationInfo>;
|
|
47
|
+
/**
|
|
48
|
+
* Gets the version from a config object
|
|
49
|
+
*/
|
|
50
|
+
export declare function getConfigVersion(config: unknown): string | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Compares two version strings
|
|
53
|
+
* Returns: -1 if a < b, 0 if a === b, 1 if a > b
|
|
54
|
+
*/
|
|
55
|
+
export declare function compareVersions(a: string, b: string): number;
|
|
56
|
+
/**
|
|
57
|
+
* Checks if a version is supported for migration
|
|
58
|
+
*/
|
|
59
|
+
export declare function isVersionSupported(version: string): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Gets the migration path from one version to another
|
|
62
|
+
*/
|
|
63
|
+
export declare function getMigrationPath(fromVersion: string, toVersion: string): MigrationInfo[];
|
|
64
|
+
/**
|
|
65
|
+
* Checks if a config needs migration
|
|
66
|
+
*/
|
|
67
|
+
export declare function needsMigration(config: unknown): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Migrates a config to the latest version
|
|
70
|
+
*
|
|
71
|
+
* @throws ConfigError if migration fails or version is unsupported
|
|
72
|
+
*/
|
|
73
|
+
export declare function migrateConfig(config: unknown): AutomatosXConfig;
|
|
74
|
+
/**
|
|
75
|
+
* Safely migrates a config, returning undefined on failure
|
|
76
|
+
*/
|
|
77
|
+
export declare function safeMigrateConfig(config: unknown): {
|
|
78
|
+
success: true;
|
|
79
|
+
data: AutomatosXConfig;
|
|
80
|
+
} | {
|
|
81
|
+
success: false;
|
|
82
|
+
error: ConfigError;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Gets migration info for a config
|
|
86
|
+
*/
|
|
87
|
+
export declare function getMigrationInfo(config: unknown): {
|
|
88
|
+
currentVersion: string | undefined;
|
|
89
|
+
targetVersion: string;
|
|
90
|
+
needsMigration: boolean;
|
|
91
|
+
migrationPath: MigrationInfo[];
|
|
92
|
+
};
|
|
93
|
+
//# sourceMappingURL=migrator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrator.d.ts","sourceRoot":"","sources":["../src/migrator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EACL,KAAK,gBAAgB,EAKrB,WAAW,EACZ,MAAM,0BAA0B,CAAC;AAMlC;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,+CAA+C;IAC/C,WAAW,EAAE,MAAM,CAAC;IACpB,qCAAqC;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,6BAA6B;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,yBAAyB;IACzB,OAAO,EAAE,eAAe,CAAC;CAC1B;AAMD;;GAEG;AACH,eAAO,MAAM,eAAe,UAAU,CAAC;AAEvC;;GAEG;AACH,eAAO,MAAM,qBAAqB,UAAU,CAAC;AAE7C;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,SAAS,MAAM,EAKjC,CAAC;AAMX;;;GAGG;AACH,eAAO,MAAM,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAkEpD,CAAC;AAMF;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAUpE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAU5D;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAE3D;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,aAAa,EAAE,CAgBxF;AAMD;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAevD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,OAAO,GAAG,gBAAgB,CAsE/D;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,OAAO,GACd;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,gBAAgB,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,WAAW,CAAA;CAAE,CAiBpF;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,OAAO,GAAG;IACjD,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,OAAO,CAAC;IACxB,aAAa,EAAE,aAAa,EAAE,CAAC;CAChC,CAYA"}
|
package/dist/migrator.js
ADDED
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config Version Migration
|
|
3
|
+
*
|
|
4
|
+
* Handles schema migrations for configuration files across versions.
|
|
5
|
+
*
|
|
6
|
+
* Invariants:
|
|
7
|
+
* - INV-CFG-MIG-001: Migrations are idempotent
|
|
8
|
+
* - INV-CFG-MIG-002: Version order is strictly increasing
|
|
9
|
+
* - INV-CFG-MIG-003: Unknown versions fail fast
|
|
10
|
+
*/
|
|
11
|
+
import { validateConfig, safeValidateConfig, DEFAULT_CONFIG, ConfigErrorCode, ConfigError, } from '@defai.digital/contracts';
|
|
12
|
+
// ============================================================================
|
|
13
|
+
// Version Constants
|
|
14
|
+
// ============================================================================
|
|
15
|
+
/**
|
|
16
|
+
* Current config schema version
|
|
17
|
+
*/
|
|
18
|
+
export const CURRENT_VERSION = '1.0.0';
|
|
19
|
+
/**
|
|
20
|
+
* Minimum supported version (older versions cannot be migrated)
|
|
21
|
+
*/
|
|
22
|
+
export const MIN_SUPPORTED_VERSION = '0.9.0';
|
|
23
|
+
/**
|
|
24
|
+
* Version order for migration path calculation
|
|
25
|
+
*/
|
|
26
|
+
export const VERSION_ORDER = [
|
|
27
|
+
'0.9.0',
|
|
28
|
+
'0.9.1',
|
|
29
|
+
'0.10.0',
|
|
30
|
+
'1.0.0',
|
|
31
|
+
];
|
|
32
|
+
// ============================================================================
|
|
33
|
+
// Migration Registry
|
|
34
|
+
// ============================================================================
|
|
35
|
+
/**
|
|
36
|
+
* Registered migrations by source version
|
|
37
|
+
* Each migration transforms config from fromVersion to toVersion
|
|
38
|
+
*/
|
|
39
|
+
export const MIGRATIONS = {
|
|
40
|
+
// Example migration from 0.9.0 to 0.9.1
|
|
41
|
+
'0.9.0': {
|
|
42
|
+
fromVersion: '0.9.0',
|
|
43
|
+
toVersion: '0.9.1',
|
|
44
|
+
description: 'Add features field with defaults',
|
|
45
|
+
migrate: (config) => {
|
|
46
|
+
const cfg = config;
|
|
47
|
+
return {
|
|
48
|
+
...cfg,
|
|
49
|
+
features: cfg.features ?? DEFAULT_CONFIG.features,
|
|
50
|
+
version: '0.9.1',
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
// Migration from 0.9.1 to 0.10.0
|
|
55
|
+
'0.9.1': {
|
|
56
|
+
fromVersion: '0.9.1',
|
|
57
|
+
toVersion: '0.10.0',
|
|
58
|
+
description: 'Add workspace configuration field',
|
|
59
|
+
migrate: (config) => {
|
|
60
|
+
const cfg = config;
|
|
61
|
+
return {
|
|
62
|
+
...cfg,
|
|
63
|
+
workspace: cfg.workspace ?? DEFAULT_CONFIG.workspace,
|
|
64
|
+
version: '0.10.0',
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
// Migration from 0.10.0 to 1.0.0
|
|
69
|
+
'0.10.0': {
|
|
70
|
+
fromVersion: '0.10.0',
|
|
71
|
+
toVersion: '1.0.0',
|
|
72
|
+
description: 'Stable release - normalize provider configuration to Record format',
|
|
73
|
+
migrate: (config) => {
|
|
74
|
+
const cfg = config;
|
|
75
|
+
// Convert providers from array to Record format if needed
|
|
76
|
+
let providers = {};
|
|
77
|
+
if (Array.isArray(cfg.providers)) {
|
|
78
|
+
// Convert array format to Record format
|
|
79
|
+
for (const p of cfg.providers) {
|
|
80
|
+
const provider = p;
|
|
81
|
+
const providerId = provider.providerId;
|
|
82
|
+
if (providerId) {
|
|
83
|
+
providers[providerId] = {
|
|
84
|
+
enabled: provider.enabled ?? true,
|
|
85
|
+
priority: provider.priority ?? 50,
|
|
86
|
+
command: provider.command,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else if (cfg.providers && typeof cfg.providers === 'object') {
|
|
92
|
+
// Already in Record format
|
|
93
|
+
providers = cfg.providers;
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
...cfg,
|
|
97
|
+
providers,
|
|
98
|
+
version: '1.0.0',
|
|
99
|
+
};
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
// ============================================================================
|
|
104
|
+
// Version Utilities
|
|
105
|
+
// ============================================================================
|
|
106
|
+
/**
|
|
107
|
+
* Gets the version from a config object
|
|
108
|
+
*/
|
|
109
|
+
export function getConfigVersion(config) {
|
|
110
|
+
if (config === null || typeof config !== 'object') {
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
const cfg = config;
|
|
114
|
+
const version = cfg.version;
|
|
115
|
+
if (typeof version !== 'string') {
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
return version;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Compares two version strings
|
|
122
|
+
* Returns: -1 if a < b, 0 if a === b, 1 if a > b
|
|
123
|
+
*/
|
|
124
|
+
export function compareVersions(a, b) {
|
|
125
|
+
const indexA = VERSION_ORDER.indexOf(a);
|
|
126
|
+
const indexB = VERSION_ORDER.indexOf(b);
|
|
127
|
+
// Unknown versions sort to end
|
|
128
|
+
if (indexA === -1 && indexB === -1)
|
|
129
|
+
return 0;
|
|
130
|
+
if (indexA === -1)
|
|
131
|
+
return 1;
|
|
132
|
+
if (indexB === -1)
|
|
133
|
+
return -1;
|
|
134
|
+
return indexA - indexB;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Checks if a version is supported for migration
|
|
138
|
+
*/
|
|
139
|
+
export function isVersionSupported(version) {
|
|
140
|
+
return VERSION_ORDER.includes(version);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Gets the migration path from one version to another
|
|
144
|
+
*/
|
|
145
|
+
export function getMigrationPath(fromVersion, toVersion) {
|
|
146
|
+
const path = [];
|
|
147
|
+
let currentVersion = fromVersion;
|
|
148
|
+
while (compareVersions(currentVersion, toVersion) < 0) {
|
|
149
|
+
const migration = MIGRATIONS[currentVersion];
|
|
150
|
+
if (migration === undefined) {
|
|
151
|
+
// No migration available for this version
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
path.push(migration);
|
|
155
|
+
currentVersion = migration.toVersion;
|
|
156
|
+
}
|
|
157
|
+
return path;
|
|
158
|
+
}
|
|
159
|
+
// ============================================================================
|
|
160
|
+
// Migration Functions
|
|
161
|
+
// ============================================================================
|
|
162
|
+
/**
|
|
163
|
+
* Checks if a config needs migration
|
|
164
|
+
*/
|
|
165
|
+
export function needsMigration(config) {
|
|
166
|
+
const version = getConfigVersion(config);
|
|
167
|
+
// No version field - needs migration to add it
|
|
168
|
+
if (version === undefined) {
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
// Already at current version
|
|
172
|
+
if (version === CURRENT_VERSION) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
// Check if we have a migration path
|
|
176
|
+
return compareVersions(version, CURRENT_VERSION) < 0;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Migrates a config to the latest version
|
|
180
|
+
*
|
|
181
|
+
* @throws ConfigError if migration fails or version is unsupported
|
|
182
|
+
*/
|
|
183
|
+
export function migrateConfig(config) {
|
|
184
|
+
// Handle null/undefined
|
|
185
|
+
if (config === null || config === undefined) {
|
|
186
|
+
return { ...DEFAULT_CONFIG, version: CURRENT_VERSION };
|
|
187
|
+
}
|
|
188
|
+
// Get current version
|
|
189
|
+
let version = getConfigVersion(config);
|
|
190
|
+
// If no version, assume oldest supported version
|
|
191
|
+
if (version === undefined) {
|
|
192
|
+
version = MIN_SUPPORTED_VERSION;
|
|
193
|
+
config = { ...config, version };
|
|
194
|
+
}
|
|
195
|
+
// Check if version is supported
|
|
196
|
+
if (!isVersionSupported(version)) {
|
|
197
|
+
throw new ConfigError(ConfigErrorCode.CONFIG_MIGRATION_FAILED, `Config version ${version} is not supported. Minimum supported version is ${MIN_SUPPORTED_VERSION}`, { version, minSupported: MIN_SUPPORTED_VERSION });
|
|
198
|
+
}
|
|
199
|
+
// Already at current version - validate and return
|
|
200
|
+
if (version === CURRENT_VERSION) {
|
|
201
|
+
const result = safeValidateConfig(config);
|
|
202
|
+
if (!result.success) {
|
|
203
|
+
throw new ConfigError(ConfigErrorCode.CONFIG_VALIDATION_ERROR, 'Config validation failed after migration', { errors: result.error.errors.map((e) => e.message) });
|
|
204
|
+
}
|
|
205
|
+
return result.data;
|
|
206
|
+
}
|
|
207
|
+
// Get migration path
|
|
208
|
+
const migrations = getMigrationPath(version, CURRENT_VERSION);
|
|
209
|
+
if (migrations.length === 0) {
|
|
210
|
+
throw new ConfigError(ConfigErrorCode.CONFIG_MIGRATION_FAILED, `No migration path found from version ${version} to ${CURRENT_VERSION}`, { fromVersion: version, toVersion: CURRENT_VERSION });
|
|
211
|
+
}
|
|
212
|
+
// Apply migrations in order
|
|
213
|
+
let migratedConfig = config;
|
|
214
|
+
for (const migration of migrations) {
|
|
215
|
+
try {
|
|
216
|
+
migratedConfig = migration.migrate(migratedConfig);
|
|
217
|
+
}
|
|
218
|
+
catch (error) {
|
|
219
|
+
throw new ConfigError(ConfigErrorCode.CONFIG_MIGRATION_FAILED, `Migration from ${migration.fromVersion} to ${migration.toVersion} failed: ${error instanceof Error ? error.message : 'Unknown error'}`, {
|
|
220
|
+
fromVersion: migration.fromVersion,
|
|
221
|
+
toVersion: migration.toVersion,
|
|
222
|
+
error: String(error),
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
// Validate final result
|
|
227
|
+
const validated = validateConfig(migratedConfig);
|
|
228
|
+
return validated;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Safely migrates a config, returning undefined on failure
|
|
232
|
+
*/
|
|
233
|
+
export function safeMigrateConfig(config) {
|
|
234
|
+
try {
|
|
235
|
+
const result = migrateConfig(config);
|
|
236
|
+
return { success: true, data: result };
|
|
237
|
+
}
|
|
238
|
+
catch (error) {
|
|
239
|
+
if (error instanceof ConfigError) {
|
|
240
|
+
return { success: false, error };
|
|
241
|
+
}
|
|
242
|
+
return {
|
|
243
|
+
success: false,
|
|
244
|
+
error: new ConfigError(ConfigErrorCode.CONFIG_MIGRATION_FAILED, error instanceof Error ? error.message : 'Unknown migration error', { error: String(error) }),
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Gets migration info for a config
|
|
250
|
+
*/
|
|
251
|
+
export function getMigrationInfo(config) {
|
|
252
|
+
const currentVersion = getConfigVersion(config);
|
|
253
|
+
const effectiveVersion = currentVersion ?? MIN_SUPPORTED_VERSION;
|
|
254
|
+
const requires = needsMigration(config);
|
|
255
|
+
const path = requires ? getMigrationPath(effectiveVersion, CURRENT_VERSION) : [];
|
|
256
|
+
return {
|
|
257
|
+
currentVersion,
|
|
258
|
+
targetVersion: CURRENT_VERSION,
|
|
259
|
+
needsMigration: requires,
|
|
260
|
+
migrationPath: path,
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
//# sourceMappingURL=migrator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrator.js","sourceRoot":"","sources":["../src/migrator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAEL,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,eAAe,EACf,WAAW,GACZ,MAAM,0BAA0B,CAAC;AA0BlC,+EAA+E;AAC/E,oBAAoB;AACpB,+EAA+E;AAE/E;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,OAAO,CAAC;AAEvC;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,OAAO,CAAC;AAE7C;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAsB;IAC9C,OAAO;IACP,OAAO;IACP,QAAQ;IACR,OAAO;CACC,CAAC;AAEX,+EAA+E;AAC/E,qBAAqB;AACrB,+EAA+E;AAE/E;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAkC;IACvD,wCAAwC;IACxC,OAAO,EAAE;QACP,WAAW,EAAE,OAAO;QACpB,SAAS,EAAE,OAAO;QAClB,WAAW,EAAE,kCAAkC;QAC/C,OAAO,EAAE,CAAC,MAAe,EAAW,EAAE;YACpC,MAAM,GAAG,GAAG,MAAiC,CAAC;YAC9C,OAAO;gBACL,GAAG,GAAG;gBACN,QAAQ,EAAE,GAAG,CAAC,QAAQ,IAAI,cAAc,CAAC,QAAQ;gBACjD,OAAO,EAAE,OAAO;aACjB,CAAC;QACJ,CAAC;KACF;IAED,iCAAiC;IACjC,OAAO,EAAE;QACP,WAAW,EAAE,OAAO;QACpB,SAAS,EAAE,QAAQ;QACnB,WAAW,EAAE,mCAAmC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C,gBAAgB,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAEjF,OAAO;QACL,cAAc;QACd,aAAa,EAAE,eAAe;QAC9B,cAAc,EAAE,QAAQ;QACxB,aAAa,EAAE,IAAI;KACpB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration Operations
|
|
3
|
+
*
|
|
4
|
+
* Pure functions for config manipulation (immutable operations).
|
|
5
|
+
*/
|
|
6
|
+
import type { AutomatosXConfig } from '@defai.digital/contracts';
|
|
7
|
+
/**
|
|
8
|
+
* Parses a config path into segments
|
|
9
|
+
* @example parsePath('providers.0.providerId') => ['providers', '0', 'providerId']
|
|
10
|
+
*/
|
|
11
|
+
export declare function parsePath(path: string): string[];
|
|
12
|
+
/**
|
|
13
|
+
* Gets a value from config by path
|
|
14
|
+
* @example getValue(config, 'providers.0.providerId') => 'claude'
|
|
15
|
+
*/
|
|
16
|
+
export declare function getValue<T>(config: AutomatosXConfig, path: string): T | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Sets a value in config by path (immutable)
|
|
19
|
+
* @example setValue(config, 'logLevel', 'debug') => new config with updated logLevel
|
|
20
|
+
*/
|
|
21
|
+
export declare function setValue(config: AutomatosXConfig, path: string, value: unknown): AutomatosXConfig;
|
|
22
|
+
/**
|
|
23
|
+
* Removes a value from config by path (immutable)
|
|
24
|
+
*/
|
|
25
|
+
export declare function removeValue(config: AutomatosXConfig, path: string): AutomatosXConfig;
|
|
26
|
+
/**
|
|
27
|
+
* Deep merges two configs (immutable)
|
|
28
|
+
* Override values take precedence
|
|
29
|
+
*/
|
|
30
|
+
export declare function mergeConfigs(base: AutomatosXConfig, override: Partial<AutomatosXConfig>): AutomatosXConfig;
|
|
31
|
+
/**
|
|
32
|
+
* Compares two configs and returns the differences
|
|
33
|
+
*/
|
|
34
|
+
export declare function diffConfigs(oldConfig: AutomatosXConfig, newConfig: AutomatosXConfig): {
|
|
35
|
+
path: string;
|
|
36
|
+
oldValue: unknown;
|
|
37
|
+
newValue: unknown;
|
|
38
|
+
}[];
|
|
39
|
+
/**
|
|
40
|
+
* Checks if a path exists in the config
|
|
41
|
+
*/
|
|
42
|
+
export declare function hasPath(config: AutomatosXConfig, path: string): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Gets all paths in a config (flattened)
|
|
45
|
+
*/
|
|
46
|
+
export declare function getAllPaths(config: AutomatosXConfig): string[];
|
|
47
|
+
//# sourceMappingURL=operations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../src/operations.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAMjE;;;GAGG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAKhD;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EACxB,MAAM,EAAE,gBAAgB,EACxB,IAAI,EAAE,MAAM,GACX,CAAC,GAAG,SAAS,CAyBf;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CACtB,MAAM,EAAE,gBAAgB,EACxB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,GACb,gBAAgB,CAOlB;AA6CD;;GAEG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,gBAAgB,EACxB,IAAI,EAAE,MAAM,GACX,gBAAgB,CAOlB;AA8DD;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,gBAAgB,EACtB,QAAQ,EAAE,OAAO,CAAC,gBAAgB,CAAC,GAClC,gBAAgB,CAElB;AA2CD;;GAEG;AACH,wBAAgB,WAAW,CACzB,SAAS,EAAE,gBAAgB,EAC3B,SAAS,EAAE,gBAAgB,GAC1B;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,EAAE,CAmD1D;AAMD;;GAEG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAEvE;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,gBAAgB,GAAG,MAAM,EAAE,CAkC9D"}
|