@adminide-stack/core 12.0.4-alpha.321 → 12.0.4-alpha.322
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/lib/core/configurations/examples/configuration-wrapper-example.d.ts +67 -0
- package/lib/core/configurations/models/ConfigurationModelWrapper.d.ts +4 -0
- package/lib/core/configurations/models/ConfigurationModelWrapper.js +24 -2
- package/lib/core/configurations/models/ConfigurationModelWrapper.js.map +1 -1
- package/lib/core/configurations/models/ConfigurationModelWrapper.spec.d.ts +1 -0
- package/lib/core/configurations/models/override.compound.test.d.ts +1 -0
- package/lib/core/configurations/models/override.edgecase.test.d.ts +1 -0
- package/lib/core/configurations/models/override.keys.test.d.ts +1 -0
- package/lib/core/configurations/models/override.strict.test.d.ts +1 -0
- package/lib/core/configurations/utils/QUICK_REFERENCE.d.ts +103 -0
- package/lib/core/configurations/utils/configurationExtractor.d.ts +182 -0
- package/lib/core/configurations/utils/configurationExtractor.test.d.ts +1 -0
- package/lib/core/configurations/utils/index.d.ts +5 -0
- package/lib/core/configurations/utils/preferences-service-integration.d.ts +54 -0
- package/lib/core/configurations/utils/usage-examples.d.ts +39 -0
- package/package.json +3 -3
- /package/lib/core/configurations/{models/ConfigurationModelWrapper.test.d.ts → examples/configuration-wrapper.test.d.ts} +0 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { ConfigurationModel } from '../models/ConfigurationModel';
|
|
2
|
+
/**
|
|
3
|
+
* Example: Creating a ConfigurationModel from your complex configuration data
|
|
4
|
+
*
|
|
5
|
+
* This demonstrates how to:
|
|
6
|
+
* 1. Parse raw JSON configuration with override identifiers
|
|
7
|
+
* 2. Create a ConfigurationModel instance
|
|
8
|
+
* 3. Apply overrides for specific routes/contexts
|
|
9
|
+
* 4. Access configuration values with proper merging
|
|
10
|
+
*/
|
|
11
|
+
declare const rawConfigurationJSON = "{\n \"headerBgColor\": \"#000000\",\n \"textColor\": \"#a19c9c\",\n \"project\": {\n \"templates\": {\n \"default\": {\n \"id\": \"default\",\n \"name\": \"Default Project\",\n \"templateType\": \"default\",\n \"description\": \"Basic project template with essential fields\",\n \"isDefault\": true,\n \"component\": \"DefaultProjectSlotFill\",\n \"fields\": [\n {\n \"id\": \"budget\",\n \"type\": \"text\",\n \"label\": \"Budget\",\n \"placeholder\": \"Enter project budget\",\n \"required\": true\n },\n {\n \"id\": \"deadline\",\n \"type\": \"date\",\n \"label\": \"Deadline\",\n \"required\": true\n },\n {\n \"id\": \"priority\",\n \"type\": \"select\",\n \"label\": \"Priority\",\n \"required\": true,\n \"options\": [\"Low\", \"Medium\", \"High\", \"Critical\"]\n },\n {\n \"id\": \"description\",\n \"type\": \"textarea\",\n \"label\": \"Project Description\",\n \"placeholder\": \"Describe the project objectives and scope\",\n \"required\": false\n }\n ],\n \"isActive\": true,\n \"order\": 1\n },\n \"software\": {\n \"id\": \"software\",\n \"name\": \"Software Development\",\n \"templateType\": \"software\",\n \"description\": \"Template for software development projects\",\n \"component\": \"SoftwareProjectSlotFill\",\n \"fields\": [\n {\n \"id\": \"technology_stack\",\n \"type\": \"select\",\n \"label\": \"Technology Stack\",\n \"required\": true,\n \"options\": [\"React/Node.js\", \"Vue/Express\", \"Angular/NestJS\", \"Python/Django\", \"Other\"]\n },\n {\n \"id\": \"project_type\",\n \"type\": \"select\",\n \"label\": \"Project Type\",\n \"required\": true,\n \"options\": [\"Web Application\", \"Mobile App\", \"Desktop Application\", \"API/Backend\"]\n },\n {\n \"id\": \"estimated_hours\",\n \"type\": \"number\",\n \"label\": \"Estimated Hours\",\n \"placeholder\": \"Enter estimated development hours\",\n \"required\": true\n },\n {\n \"id\": \"client_contact\",\n \"type\": \"email\",\n \"label\": \"Client Contact Email\",\n \"required\": false\n }\n ],\n \"isActive\": true,\n \"order\": 2\n },\n \"marketing\": {\n \"id\": \"marketing\",\n \"name\": \"Marketing Campaign\",\n \"templateType\": \"marketing\",\n \"description\": \"Template for marketing and advertising projects\",\n \"component\": \"MarketingProjectSlotFill\",\n \"fields\": [\n {\n \"id\": \"campaign_type\",\n \"type\": \"select\",\n \"label\": \"Campaign Type\",\n \"required\": true,\n \"options\": [\"Social Media\", \"Email Marketing\", \"Content Marketing\", \"PPC\", \"SEO\"]\n },\n {\n \"id\": \"target_audience\",\n \"type\": \"text\",\n \"label\": \"Target Audience\",\n \"placeholder\": \"Describe the target demographic\",\n \"required\": true\n },\n {\n \"id\": \"campaign_duration\",\n \"type\": \"number\",\n \"label\": \"Campaign Duration (weeks)\",\n \"required\": true\n },\n {\n \"id\": \"kpis\",\n \"type\": \"textarea\",\n \"label\": \"Key Performance Indicators\",\n \"placeholder\": \"List the KPIs to track campaign success\",\n \"required\": false\n }\n ],\n \"isActive\": true,\n \"order\": 3\n },\n \"database\": {\n \"id\": \"database\",\n \"name\": \"Database Project\",\n \"templateType\": \"database\",\n \"description\": \"Template for database creation and management projects\",\n \"component\": \"DatabaseProjectSlotFill\",\n \"fields\": [\n {\n \"id\": \"organization\",\n \"type\": \"select\",\n \"label\": \"Organization\",\n \"required\": true,\n \"options\": [\"stackflow1@gmail.com's Org (Free)\", \"Personal Account\", \"Enterprise Account\"]\n },\n {\n \"id\": \"project_name\",\n \"type\": \"text\",\n \"label\": \"Project Name\",\n \"placeholder\": \"Enter unique project identifier\",\n \"required\": true\n },\n {\n \"id\": \"database_password\",\n \"type\": \"text\",\n \"label\": \"Database Password\",\n \"placeholder\": \"Auto-generated secure password\",\n \"required\": true\n },\n {\n \"id\": \"region\",\n \"type\": \"select\",\n \"label\": \"Region\",\n \"required\": true,\n \"options\": [\"Southeast Asia (Singapore)\", \"US East (N. Virginia)\", \"US West (Oregon)\", \"Europe (Frankfurt)\", \"Asia Pacific (Tokyo)\", \"Canada (Central)\", \"Australia (Sydney)\"]\n },\n {\n \"id\": \"connection_type\",\n \"type\": \"select\",\n \"label\": \"Connection Type\",\n \"required\": true,\n \"options\": [\"Data API + Connection String\", \"Only Connection String\"]\n },\n {\n \"id\": \"api_schema\",\n \"type\": \"select\",\n \"label\": \"Data API Configuration\",\n \"required\": true,\n \"options\": [\"Use public schema for Data API (Default)\", \"Use dedicated API schema for Data API\"]\n },\n {\n \"id\": \"postgres_type\",\n \"type\": \"select\",\n \"label\": \"PostgreSQL Type\",\n \"required\": true,\n \"options\": [\"PostgreSQL (Default)\", \"PostgreSQL with OrioleDB (Alpha)\"]\n },\n {\n \"id\": \"performance_tier\",\n \"type\": \"select\",\n \"label\": \"Performance Tier\",\n \"required\": false,\n \"options\": [\"Free Tier\", \"Pro\", \"Team\", \"Enterprise\"]\n },\n {\n \"id\": \"backup_enabled\",\n \"type\": \"checkbox\",\n \"label\": \"Enable Automated Backups\",\n \"required\": false\n },\n {\n \"id\": \"ssl_enforcement\",\n \"type\": \"checkbox\",\n \"label\": \"Enforce SSL Connections\",\n \"required\": false\n },\n {\n \"id\": \"description\",\n \"type\": \"textarea\",\n \"label\": \"Project Description\",\n \"placeholder\": \"Describe the database purpose and expected usage patterns\",\n \"required\": false\n }\n ],\n \"isActive\": true,\n \"order\": 4\n },\n \"enabled\": true\n }\n },\n \"[/o/:orgName/vault]\": {\n \"navTheme\": \"realDark\",\n \"primaryColor\": \"#1890ff\",\n \"theme\": \"airbnb\",\n \"footer\": {\n \"showFooter\": false\n }\n },\n \"[/o/:orgName/pref/settings]\": {\n \"header\": {\n \"menuHeaderRender\": false\n }\n }\n}";
|
|
12
|
+
/**
|
|
13
|
+
* Wrapper class for working with configuration models
|
|
14
|
+
*/
|
|
15
|
+
export declare class ConfigurationWrapper {
|
|
16
|
+
private rawJSON;
|
|
17
|
+
private baseModel;
|
|
18
|
+
constructor(rawJSON: string);
|
|
19
|
+
/**
|
|
20
|
+
* Parse the configuration and create the base model
|
|
21
|
+
*/
|
|
22
|
+
initialize(configurationProperties?: any): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Get the base configuration model
|
|
25
|
+
*/
|
|
26
|
+
getBaseModel(): ConfigurationModel;
|
|
27
|
+
/**
|
|
28
|
+
* Get a value from the base configuration (no overrides applied)
|
|
29
|
+
*/
|
|
30
|
+
getBaseValue<T = any>(section?: string): T;
|
|
31
|
+
/**
|
|
32
|
+
* Get configuration with overrides applied for a specific route
|
|
33
|
+
*
|
|
34
|
+
* @param routeIdentifier - e.g., "/o/:orgName/vault"
|
|
35
|
+
* @param strict - If true, only exact matches; if false, includes compound overrides
|
|
36
|
+
*/
|
|
37
|
+
getConfigForRoute<T = any>(routeIdentifier: string, strict?: boolean): T;
|
|
38
|
+
/**
|
|
39
|
+
* Get a specific section with route overrides applied
|
|
40
|
+
*/
|
|
41
|
+
getSectionForRoute<T = any>(section: string, routeIdentifier: string, strict?: boolean): T;
|
|
42
|
+
/**
|
|
43
|
+
* Get all available override identifiers
|
|
44
|
+
*/
|
|
45
|
+
getOverrideIdentifiers(): string[][];
|
|
46
|
+
/**
|
|
47
|
+
* Check if a specific override exists
|
|
48
|
+
*/
|
|
49
|
+
hasOverride(identifier: string): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Merge multiple configuration models
|
|
52
|
+
*/
|
|
53
|
+
merge(other: ConfigurationModel): void;
|
|
54
|
+
/**
|
|
55
|
+
* Get all keys in the configuration
|
|
56
|
+
*/
|
|
57
|
+
getKeys(): string[];
|
|
58
|
+
/**
|
|
59
|
+
* Print debug information
|
|
60
|
+
*/
|
|
61
|
+
debug(): void;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Example usage demonstrating the wrapper
|
|
65
|
+
*/
|
|
66
|
+
export declare function exampleUsage(): Promise<void>;
|
|
67
|
+
export { rawConfigurationJSON };
|
|
@@ -22,6 +22,10 @@ export declare class EnhancedConfigurationModel {
|
|
|
22
22
|
* @returns Value merged with base + identifier, and compound overrides as additional keys
|
|
23
23
|
*/
|
|
24
24
|
getValue<T>(section?: string): T;
|
|
25
|
+
/**
|
|
26
|
+
* Filter out bracket-notation keys from an object
|
|
27
|
+
*/
|
|
28
|
+
private filterBracketKeys;
|
|
25
29
|
/**
|
|
26
30
|
* Get all available compound override keys (without the current identifier)
|
|
27
31
|
*/
|
|
@@ -47,13 +47,19 @@ class EnhancedConfigurationModel {
|
|
|
47
47
|
getValue(section) {
|
|
48
48
|
// Get the merged value (base + identifier override)
|
|
49
49
|
const mergedValue = section ? this.overrideModel.getValue(section) : this.overrideModel.contents;
|
|
50
|
-
// If no compound overrides, return as-is
|
|
50
|
+
// If no compound overrides, return as-is (but filter out bracket keys if no section)
|
|
51
51
|
if (this.compoundOverrides.size === 0) {
|
|
52
|
+
if (!section) {
|
|
53
|
+
// Filter out any bracket-notation keys from the result
|
|
54
|
+
return this.filterBracketKeys(mergedValue);
|
|
55
|
+
}
|
|
52
56
|
return mergedValue;
|
|
53
57
|
}
|
|
54
58
|
// Create result object with merged value and compound overrides
|
|
59
|
+
// When no section is specified, filter out bracket keys from base contents
|
|
60
|
+
const baseResult = section ? mergedValue : this.filterBracketKeys(mergedValue);
|
|
55
61
|
const result = {
|
|
56
|
-
...(
|
|
62
|
+
...(baseResult || {})
|
|
57
63
|
};
|
|
58
64
|
// Add compound overrides as separate keys
|
|
59
65
|
for (const [key, contents] of this.compoundOverrides.entries()) {
|
|
@@ -66,6 +72,22 @@ class EnhancedConfigurationModel {
|
|
|
66
72
|
}
|
|
67
73
|
return result;
|
|
68
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Filter out bracket-notation keys from an object
|
|
77
|
+
*/
|
|
78
|
+
filterBracketKeys(obj) {
|
|
79
|
+
if (!obj || typeof obj !== 'object') {
|
|
80
|
+
return obj;
|
|
81
|
+
}
|
|
82
|
+
const filtered = {};
|
|
83
|
+
for (const key of Object.keys(obj)) {
|
|
84
|
+
// Skip keys that start with '[' (bracket notation)
|
|
85
|
+
if (!key.startsWith('[')) {
|
|
86
|
+
filtered[key] = obj[key];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return filtered;
|
|
90
|
+
}
|
|
69
91
|
/**
|
|
70
92
|
* Get all available compound override keys (without the current identifier)
|
|
71
93
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfigurationModelWrapper.js","sources":["../../../../src/core/configurations/models/ConfigurationModelWrapper.ts"],"sourcesContent":[null],"names":[],"mappings":"AAIA;;AAEG;MACU,0BAA0B,CAAA;AAMvB,EAAA,SAAA;AACA,EAAA,UAAA;AACA,EAAA,OAAA;AAPJ,EAAA,aAAA;AAEA,EAAA,iBAAA;AAER,EAAA,WAAA,CAAA,SACY,EAA6B,UAC7B,EAAkB,OAClB,EAA8B;QAF9B,CAAA,SAAA,GAAA;QACA,CAAA,UAAA,GAAA;QACA,CAAA,OAAA,GAAA;;QAGR,CAAA,aAAK,GAAA,SAAgB,CAAA,QAAU,CAAA,UAAS,EAAA,OAAY,CAAA;;AAGpD,IAAA,IAAA,CAAA,iBAAK,GAAA,IAAoB,yBAAK,EAAA;;AAGlC;;;AAGG;0BACK,GAAwB;AAC5B,IAAA,MAAA,SAAM,GAAA,IAAY,GAAA,EAAI;SAEtB,MAAK,YAAc,IAAI,CAAA,SAAK,CAAA,SAAU,EAAA;;AAElC,MAAA,IAAA,CAAA,QAAK,CAAA,WAAS,IAAA,QAAe,CAAA,WAAS,CAAA,MAAY,IAAA,CAAA,EAAM;;;;;kBAMpD,CAAA,WAAS,CAAA,QAAY,CAAA,IAAA,CAAQ,UAAM,CAAA,EAAA;;AAEnC,QAAA,MAAA,2BAAyB,CAAA,WAAS,CAAA,MAAA,CAAW,QAAQ,KAAK,IAAG,CAAE,UAAU,CAAA;;iBAGzE,GAAA,gBAAY,CAAA,GAAA,CAAA,EAAA,KAAoB,CAAC,IAAG,CAAE,CAAA,CAAE,CAAC,CAAA,IAAI,CAAE,GAAG;iBAElD,CAAA,GAAA,CAAA,GAAS,UAAU,CAAA,QAAS,CAAA;;;AAIpC,IAAA,OAAA;;AAGJ;;;;AAIG;AACH,EAAA,QAAA,CAAA,OAAY,EAAgB;;UAExB,WAAM,GAAA,OAAc,GAAA,IAAO,CAAA,aAAA,CAAA,QAAA,CAAA,OAAA,CAAA,GAAA,IAAA,CAAA,aAAA,CAAA,QAAA;;AAEvB,IAAA,IAAA,IAAA,CAAC,iBAAM,CAAA,UAAsB,EAAC;
|
|
1
|
+
{"version":3,"file":"ConfigurationModelWrapper.js","sources":["../../../../src/core/configurations/models/ConfigurationModelWrapper.ts"],"sourcesContent":[null],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* QUICK REFERENCE: Configuration Extractor Utilities
|
|
3
|
+
* ==================================================
|
|
4
|
+
*
|
|
5
|
+
* Import:
|
|
6
|
+
* import { extractConfiguration, ... } from '@adminide/core/configurations/utils';
|
|
7
|
+
*
|
|
8
|
+
* REUSES EXISTING CODE:
|
|
9
|
+
* - OVERRIDE_PROPERTY_REGEX from configuration.ts
|
|
10
|
+
* - overrideIdentifiersFromKey from configuration.ts
|
|
11
|
+
*
|
|
12
|
+
* ==================================================
|
|
13
|
+
* MAIN FUNCTION
|
|
14
|
+
* ==================================================
|
|
15
|
+
*
|
|
16
|
+
* extractConfiguration(settings)
|
|
17
|
+
* Returns: { baseContents, baseKeys, overrides }
|
|
18
|
+
*
|
|
19
|
+
* Example:
|
|
20
|
+
* const { baseContents, baseKeys, overrides } = extractConfiguration({
|
|
21
|
+
* theme: "light",
|
|
22
|
+
* "[desktop]": { theme: "dark" }
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* ==================================================
|
|
26
|
+
* HELPER FUNCTIONS
|
|
27
|
+
* ==================================================
|
|
28
|
+
*
|
|
29
|
+
* isBracketKey(key: string): boolean
|
|
30
|
+
* Check if key is bracket notation: [desktop], [/route]
|
|
31
|
+
*
|
|
32
|
+
* extractIdentifiersFromKey(key: string): string[]
|
|
33
|
+
* Parse identifiers from key: "[/route][desktop]" => ["/route", "desktop"]
|
|
34
|
+
*
|
|
35
|
+
* getOverrideKeys(settings): string[]
|
|
36
|
+
* Get all bracket keys: ["[desktop]", "[mobile]"]
|
|
37
|
+
*
|
|
38
|
+
* getBaseKeys(settings): string[]
|
|
39
|
+
* Get all non-bracket keys: ["theme", "color"]
|
|
40
|
+
*
|
|
41
|
+
* removeOverrideKeys(settings): object
|
|
42
|
+
* Return new object without bracket keys
|
|
43
|
+
*
|
|
44
|
+
* hasOverrides(settings): boolean
|
|
45
|
+
* Check if settings has any overrides
|
|
46
|
+
*
|
|
47
|
+
* getOverrideByIdentifier(settings, identifier): contents | undefined
|
|
48
|
+
* Get specific override: getOverrideByIdentifier(settings, "desktop")
|
|
49
|
+
*
|
|
50
|
+
* ==================================================
|
|
51
|
+
* COMMON PATTERNS
|
|
52
|
+
* ==================================================
|
|
53
|
+
*
|
|
54
|
+
* 1. EXTRACT AND SEPARATE
|
|
55
|
+
* ------------------------
|
|
56
|
+
* const { baseContents, overrides } = extractConfiguration(settings);
|
|
57
|
+
*
|
|
58
|
+
* 2. GET ROUTE CONFIG
|
|
59
|
+
* -------------------
|
|
60
|
+
* const override = overrides.find(o => o.identifiers.includes(route));
|
|
61
|
+
* const config = override ? { ...baseContents, ...override.contents } : baseContents;
|
|
62
|
+
*
|
|
63
|
+
* 3. CLEAN CONFIG
|
|
64
|
+
* ---------------
|
|
65
|
+
* const cleanConfig = removeOverrideKeys(settings);
|
|
66
|
+
*
|
|
67
|
+
* 4. CHECK FOR OVERRIDES
|
|
68
|
+
* ----------------------
|
|
69
|
+
* if (hasOverrides(settings)) { ... }
|
|
70
|
+
*
|
|
71
|
+
* 5. GET SPECIFIC OVERRIDE
|
|
72
|
+
* ------------------------
|
|
73
|
+
* const desktopConfig = getOverrideByIdentifier(settings, "desktop");
|
|
74
|
+
*
|
|
75
|
+
* ==================================================
|
|
76
|
+
* TYPES
|
|
77
|
+
* ==================================================
|
|
78
|
+
*
|
|
79
|
+
* interface ExtractedConfiguration {
|
|
80
|
+
* baseContents: any;
|
|
81
|
+
* baseKeys: string[];
|
|
82
|
+
* overrides: ConfigurationOverride[];
|
|
83
|
+
* }
|
|
84
|
+
*
|
|
85
|
+
* interface ConfigurationOverride {
|
|
86
|
+
* identifiers: string[]; // e.g., ["/o/:orgName/vault"]
|
|
87
|
+
* contents: any; // Override data
|
|
88
|
+
* keys: string[]; // Keys in override
|
|
89
|
+
* }
|
|
90
|
+
*
|
|
91
|
+
* ==================================================
|
|
92
|
+
* WHEN TO USE
|
|
93
|
+
* ==================================================
|
|
94
|
+
*
|
|
95
|
+
* ✅ Parsing server responses
|
|
96
|
+
* ✅ Client-side route handling
|
|
97
|
+
* ✅ Data transformation
|
|
98
|
+
* ✅ Testing configuration structure
|
|
99
|
+
* ✅ API response formatting
|
|
100
|
+
*
|
|
101
|
+
* ==================================================
|
|
102
|
+
*/
|
|
103
|
+
export {};
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility to extract overrides and keys from configuration data
|
|
3
|
+
*
|
|
4
|
+
* This handles bracket-notation override identifiers like:
|
|
5
|
+
* - [desktop]
|
|
6
|
+
* - [/o/:orgName/vault]
|
|
7
|
+
* - [/o/:orgName/vault][desktop]
|
|
8
|
+
*
|
|
9
|
+
* Reuses existing utilities from configuration.ts:
|
|
10
|
+
* - OVERRIDE_PROPERTY_REGEX: Pattern to match bracket keys
|
|
11
|
+
* - overrideIdentifiersFromKey: Parse identifiers from bracket notation
|
|
12
|
+
*/
|
|
13
|
+
export interface ConfigurationOverride {
|
|
14
|
+
identifiers: string[];
|
|
15
|
+
contents: any;
|
|
16
|
+
keys: string[];
|
|
17
|
+
}
|
|
18
|
+
export interface ExtractedConfiguration {
|
|
19
|
+
baseContents: any;
|
|
20
|
+
baseKeys: string[];
|
|
21
|
+
overrides: ConfigurationOverride[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Check if a key is a bracket-notation override identifier
|
|
25
|
+
* Uses OVERRIDE_PROPERTY_REGEX from configuration.ts
|
|
26
|
+
*
|
|
27
|
+
* @param key - The key to check
|
|
28
|
+
* @returns True if the key matches the override pattern
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* isBracketKey('[desktop]') // true
|
|
33
|
+
* isBracketKey('[/o/:orgName/vault]') // true
|
|
34
|
+
* isBracketKey('[/route][desktop]') // true
|
|
35
|
+
* isBracketKey('headerBgColor') // false
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function isBracketKey(key: string): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Extract individual identifiers from a bracket key
|
|
41
|
+
* Reuses overrideIdentifiersFromKey from configuration.ts
|
|
42
|
+
* Handles compound identifiers like [/route][desktop]
|
|
43
|
+
*
|
|
44
|
+
* @param key - The bracket key to parse
|
|
45
|
+
* @returns Array of identifiers without brackets
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* extractIdentifiersFromKey('[desktop]')
|
|
50
|
+
* // Returns: ['desktop']
|
|
51
|
+
*
|
|
52
|
+
* extractIdentifiersFromKey('[/o/:orgName/vault]')
|
|
53
|
+
* // Returns: ['/o/:orgName/vault']
|
|
54
|
+
*
|
|
55
|
+
* extractIdentifiersFromKey('[/o/:orgName/vault][desktop]')
|
|
56
|
+
* // Returns: ['/o/:orgName/vault', 'desktop']
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare function extractIdentifiersFromKey(key: string): string[];
|
|
60
|
+
/**
|
|
61
|
+
* Extract overrides and base configuration from settings object
|
|
62
|
+
*
|
|
63
|
+
* @param settings - Configuration object that may contain bracket-notation overrides
|
|
64
|
+
* @returns Extracted base contents, keys, and overrides array
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const settings = {
|
|
69
|
+
* headerBgColor: "#000000",
|
|
70
|
+
* textColor: "#a19c9c",
|
|
71
|
+
* "[/o/:orgName/vault]": {
|
|
72
|
+
* navTheme: "realDark",
|
|
73
|
+
* primaryColor: "#1890ff"
|
|
74
|
+
* },
|
|
75
|
+
* "[/o/:orgName/pref/settings]": {
|
|
76
|
+
* header: { menuHeaderRender: false }
|
|
77
|
+
* }
|
|
78
|
+
* };
|
|
79
|
+
*
|
|
80
|
+
* const { baseContents, baseKeys, overrides } = extractConfiguration(settings);
|
|
81
|
+
* // baseContents: { headerBgColor: "#000000", textColor: "#a19c9c" }
|
|
82
|
+
* // baseKeys: ["headerBgColor", "textColor"]
|
|
83
|
+
* // overrides: [
|
|
84
|
+
* // { identifiers: ["/o/:orgName/vault"], contents: {...}, keys: [...] },
|
|
85
|
+
* // { identifiers: ["/o/:orgName/pref/settings"], contents: {...}, keys: [...] }
|
|
86
|
+
* // ]
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export declare function extractConfiguration(settings: any): ExtractedConfiguration;
|
|
90
|
+
/**
|
|
91
|
+
* Get only the override keys (bracket-notation keys) from settings
|
|
92
|
+
*
|
|
93
|
+
* @param settings - Configuration object
|
|
94
|
+
* @returns Array of bracket keys
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```typescript
|
|
98
|
+
* const settings = {
|
|
99
|
+
* headerBgColor: "#000000",
|
|
100
|
+
* "[/o/:orgName/vault]": {...},
|
|
101
|
+
* "[desktop]": {...}
|
|
102
|
+
* };
|
|
103
|
+
*
|
|
104
|
+
* getOverrideKeys(settings)
|
|
105
|
+
* // Returns: ['[/o/:orgName/vault]', '[desktop]']
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
export declare function getOverrideKeys(settings: any): string[];
|
|
109
|
+
/**
|
|
110
|
+
* Get only the base keys (non-bracket keys) from settings
|
|
111
|
+
*
|
|
112
|
+
* @param settings - Configuration object
|
|
113
|
+
* @returns Array of base keys
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```typescript
|
|
117
|
+
* const settings = {
|
|
118
|
+
* headerBgColor: "#000000",
|
|
119
|
+
* textColor: "#a19c9c",
|
|
120
|
+
* "[/o/:orgName/vault]": {...}
|
|
121
|
+
* };
|
|
122
|
+
*
|
|
123
|
+
* getBaseKeys(settings)
|
|
124
|
+
* // Returns: ['headerBgColor', 'textColor']
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
export declare function getBaseKeys(settings: any): string[];
|
|
128
|
+
/**
|
|
129
|
+
* Remove all bracket-notation keys from an object
|
|
130
|
+
* Returns a new object with only base properties
|
|
131
|
+
*
|
|
132
|
+
* @param settings - Configuration object
|
|
133
|
+
* @returns New object without bracket keys
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```typescript
|
|
137
|
+
* const settings = {
|
|
138
|
+
* headerBgColor: "#000000",
|
|
139
|
+
* "[/o/:orgName/vault]": {...},
|
|
140
|
+
* textColor: "#a19c9c"
|
|
141
|
+
* };
|
|
142
|
+
*
|
|
143
|
+
* removeOverrideKeys(settings)
|
|
144
|
+
* // Returns: { headerBgColor: "#000000", textColor: "#a19c9c" }
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
export declare function removeOverrideKeys(settings: any): any;
|
|
148
|
+
/**
|
|
149
|
+
* Check if settings object has any override identifiers
|
|
150
|
+
*
|
|
151
|
+
* @param settings - Configuration object
|
|
152
|
+
* @returns True if any bracket keys exist
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```typescript
|
|
156
|
+
* hasOverrides({ headerBgColor: "#000" }) // false
|
|
157
|
+
* hasOverrides({ "[desktop]": {...} }) // true
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
export declare function hasOverrides(settings: any): boolean;
|
|
161
|
+
/**
|
|
162
|
+
* Get a specific override by identifier
|
|
163
|
+
*
|
|
164
|
+
* @param settings - Configuration object
|
|
165
|
+
* @param identifier - The identifier to search for (without brackets)
|
|
166
|
+
* @returns The override contents or undefined if not found
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* const settings = {
|
|
171
|
+
* "[/o/:orgName/vault]": { navTheme: "realDark" },
|
|
172
|
+
* "[desktop]": { theme: "dark" }
|
|
173
|
+
* };
|
|
174
|
+
*
|
|
175
|
+
* getOverrideByIdentifier(settings, '/o/:orgName/vault')
|
|
176
|
+
* // Returns: { navTheme: "realDark" }
|
|
177
|
+
*
|
|
178
|
+
* getOverrideByIdentifier(settings, 'desktop')
|
|
179
|
+
* // Returns: { theme: "dark" }
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
export declare function getOverrideByIdentifier(settings: any, identifier: string): any | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration utilities index
|
|
3
|
+
* Exports all utility functions for working with configuration data
|
|
4
|
+
*/
|
|
5
|
+
export { ConfigurationOverride, ExtractedConfiguration, extractConfiguration, isBracketKey, extractIdentifiersFromKey, getOverrideKeys, getBaseKeys, removeOverrideKeys, hasOverrides, getOverrideByIdentifier, } from './configurationExtractor';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integration Example: In your preferences-service.ts
|
|
3
|
+
*/
|
|
4
|
+
export declare function getPageSettings(_configKey: string, _overrideIdentifier: string, _strict: boolean): Promise<any>;
|
|
5
|
+
/**
|
|
6
|
+
* Benefits of using the utility:
|
|
7
|
+
*
|
|
8
|
+
* 1. ✅ Reuses existing OVERRIDE_PROPERTY_REGEX (consistent with parser)
|
|
9
|
+
* 2. ✅ Reuses existing overrideIdentifiersFromKey (handles compound keys properly)
|
|
10
|
+
* 3. ✅ One line instead of ~20 lines of inline logic
|
|
11
|
+
* 4. ✅ Tested and documented
|
|
12
|
+
* 5. ✅ Can be reused across your codebase
|
|
13
|
+
* 6. ✅ Properly handles edge cases (null, empty, compound identifiers)
|
|
14
|
+
* 7. ✅ TypeScript typed
|
|
15
|
+
* 8. ✅ Maintains same output structure
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Your original commented code vs utility:
|
|
19
|
+
*/
|
|
20
|
+
export declare function comparison(): void;
|
|
21
|
+
/**
|
|
22
|
+
* Complete integration example for preferences-service.ts
|
|
23
|
+
*/
|
|
24
|
+
export declare class PreferencesServiceExample {
|
|
25
|
+
getPageSettings(targets: string[], configKey?: string, overrideIdentifier?: string, strict?: boolean): Promise<{
|
|
26
|
+
contents: any;
|
|
27
|
+
keys: string[];
|
|
28
|
+
overrides: {
|
|
29
|
+
identifiers: string[];
|
|
30
|
+
contents: any;
|
|
31
|
+
}[];
|
|
32
|
+
}>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Quick reference for your use case:
|
|
36
|
+
*
|
|
37
|
+
* REPLACE THIS:
|
|
38
|
+
* -------------
|
|
39
|
+
* const baseContents: any = {};
|
|
40
|
+
* const overrides: any[] = [];
|
|
41
|
+
* Object.keys(cleanedSettings).forEach((key) => {
|
|
42
|
+
* if (key.startsWith('[') && key.endsWith(']')) {
|
|
43
|
+
* const overrideData = cleanedSettings[key];
|
|
44
|
+
* overrides.push({ identifiers: [key], contents: overrideData, keys: Object.keys(overrideData) });
|
|
45
|
+
* } else {
|
|
46
|
+
* baseContents[key] = cleanedSettings[key];
|
|
47
|
+
* }
|
|
48
|
+
* });
|
|
49
|
+
*
|
|
50
|
+
* WITH THIS:
|
|
51
|
+
* ----------
|
|
52
|
+
* import { extractConfiguration } from '@adminide/core/configurations/utils';
|
|
53
|
+
* const { baseContents, overrides } = extractConfiguration(cleanedSettings);
|
|
54
|
+
*/
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example 1: Basic Extraction
|
|
3
|
+
* Extract base configuration and overrides
|
|
4
|
+
*/
|
|
5
|
+
export declare function example1_BasicExtraction(): void;
|
|
6
|
+
/**
|
|
7
|
+
* Example 2: Working with Base Configuration
|
|
8
|
+
* Get and manipulate base configuration
|
|
9
|
+
*/
|
|
10
|
+
export declare function example2_BaseConfiguration(): void;
|
|
11
|
+
/**
|
|
12
|
+
* Example 3: Route-Specific Configuration
|
|
13
|
+
* Get configuration for a specific route
|
|
14
|
+
*/
|
|
15
|
+
export declare function example3_RouteConfiguration(): void;
|
|
16
|
+
/**
|
|
17
|
+
* Example 4: Checking and Filtering
|
|
18
|
+
* Various utility functions
|
|
19
|
+
*/
|
|
20
|
+
export declare function example4_CheckingFiltering(): void;
|
|
21
|
+
/**
|
|
22
|
+
* Example 5: Parsing Identifiers
|
|
23
|
+
* Extract identifiers from bracket keys
|
|
24
|
+
*/
|
|
25
|
+
export declare function example5_ParsingIdentifiers(): void;
|
|
26
|
+
/**
|
|
27
|
+
* Example 6: Lazy Loading Pattern
|
|
28
|
+
* Load configuration once, apply overrides as needed
|
|
29
|
+
*/
|
|
30
|
+
export declare function example6_LazyLoadingPattern(): void;
|
|
31
|
+
/**
|
|
32
|
+
* Example 7: Configuration Merging
|
|
33
|
+
* Merge multiple configuration sources
|
|
34
|
+
*/
|
|
35
|
+
export declare function example7_ConfigurationMerging(): void;
|
|
36
|
+
/**
|
|
37
|
+
* Run all examples
|
|
38
|
+
*/
|
|
39
|
+
export declare function runAllExamples(): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adminide-stack/core",
|
|
3
|
-
"version": "12.0.4-alpha.
|
|
3
|
+
"version": "12.0.4-alpha.322",
|
|
4
4
|
"description": "AdminIDE core for higher packages to depend on",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"author": "CDMBase LLC",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"vscode-uri": "^3.0.8"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"common": "12.0.4-alpha.
|
|
33
|
+
"common": "12.0.4-alpha.322"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"@common-stack/server-core": ">=0.5.21",
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"typescript": {
|
|
43
43
|
"definition": "lib/index.d.ts"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "c627a82df2d971c085eb29e575e121b003e3507d"
|
|
46
46
|
}
|