typekro 0.2.2 → 0.3.1
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 +4 -3
- package/dist/.tsbuildinfo +1 -1
- package/dist/core/composition/imperative.d.ts.map +1 -1
- package/dist/core/composition/imperative.js +15 -2
- package/dist/core/composition/imperative.js.map +1 -1
- package/dist/core/composition/typekro-runtime/typekro-runtime.d.ts.map +1 -1
- package/dist/core/composition/typekro-runtime/typekro-runtime.js +24 -25
- package/dist/core/composition/typekro-runtime/typekro-runtime.js.map +1 -1
- package/dist/core/dependencies/type-guards.d.ts.map +1 -1
- package/dist/core/dependencies/type-guards.js +7 -2
- package/dist/core/dependencies/type-guards.js.map +1 -1
- package/dist/core/deployment/engine.d.ts +13 -1
- package/dist/core/deployment/engine.d.ts.map +1 -1
- package/dist/core/deployment/engine.js +48 -3
- package/dist/core/deployment/engine.js.map +1 -1
- package/dist/core/errors.d.ts +85 -0
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js +135 -0
- package/dist/core/errors.js.map +1 -1
- package/dist/core/evaluation/cel-optimizer.d.ts.map +1 -1
- package/dist/core/evaluation/cel-optimizer.js +7 -13
- package/dist/core/evaluation/cel-optimizer.js.map +1 -1
- package/dist/core/expressions/analyzer.d.ts +584 -0
- package/dist/core/expressions/analyzer.d.ts.map +1 -0
- package/dist/core/expressions/analyzer.js +2956 -0
- package/dist/core/expressions/analyzer.js.map +1 -0
- package/dist/core/expressions/cache.d.ts +136 -0
- package/dist/core/expressions/cache.d.ts.map +1 -0
- package/dist/core/expressions/cache.js +347 -0
- package/dist/core/expressions/cache.js.map +1 -0
- package/dist/core/expressions/cel-conversion-engine.d.ts +126 -0
- package/dist/core/expressions/cel-conversion-engine.d.ts.map +1 -0
- package/dist/core/expressions/cel-conversion-engine.js +293 -0
- package/dist/core/expressions/cel-conversion-engine.js.map +1 -0
- package/dist/core/expressions/compile-time-validation.d.ts +270 -0
- package/dist/core/expressions/compile-time-validation.d.ts.map +1 -0
- package/dist/core/expressions/compile-time-validation.js +506 -0
- package/dist/core/expressions/compile-time-validation.js.map +1 -0
- package/dist/core/expressions/composition-integration.d.ts +315 -0
- package/dist/core/expressions/composition-integration.d.ts.map +1 -0
- package/dist/core/expressions/composition-integration.js +936 -0
- package/dist/core/expressions/composition-integration.js.map +1 -0
- package/dist/core/expressions/conditional-expression-processor.d.ts +154 -0
- package/dist/core/expressions/conditional-expression-processor.d.ts.map +1 -0
- package/dist/core/expressions/conditional-expression-processor.js +479 -0
- package/dist/core/expressions/conditional-expression-processor.js.map +1 -0
- package/dist/core/expressions/conditional-integration.d.ts +133 -0
- package/dist/core/expressions/conditional-integration.d.ts.map +1 -0
- package/dist/core/expressions/conditional-integration.js +293 -0
- package/dist/core/expressions/conditional-integration.js.map +1 -0
- package/dist/core/expressions/conditional-validation.d.ts +181 -0
- package/dist/core/expressions/conditional-validation.d.ts.map +1 -0
- package/dist/core/expressions/conditional-validation.js +460 -0
- package/dist/core/expressions/conditional-validation.js.map +1 -0
- package/dist/core/expressions/context-aware-generator.d.ts +127 -0
- package/dist/core/expressions/context-aware-generator.d.ts.map +1 -0
- package/dist/core/expressions/context-aware-generator.js +500 -0
- package/dist/core/expressions/context-aware-generator.js.map +1 -0
- package/dist/core/expressions/context-detector.d.ts +148 -0
- package/dist/core/expressions/context-detector.d.ts.map +1 -0
- package/dist/core/expressions/context-detector.js +546 -0
- package/dist/core/expressions/context-detector.js.map +1 -0
- package/dist/core/expressions/context-switcher.d.ts +185 -0
- package/dist/core/expressions/context-switcher.d.ts.map +1 -0
- package/dist/core/expressions/context-switcher.js +515 -0
- package/dist/core/expressions/context-switcher.js.map +1 -0
- package/dist/core/expressions/context-validator.d.ts +176 -0
- package/dist/core/expressions/context-validator.d.ts.map +1 -0
- package/dist/core/expressions/context-validator.js +452 -0
- package/dist/core/expressions/context-validator.js.map +1 -0
- package/dist/core/expressions/custom-context-manager.d.ts +194 -0
- package/dist/core/expressions/custom-context-manager.d.ts.map +1 -0
- package/dist/core/expressions/custom-context-manager.js +390 -0
- package/dist/core/expressions/custom-context-manager.js.map +1 -0
- package/dist/core/expressions/expression-proxy.d.ts +80 -0
- package/dist/core/expressions/expression-proxy.d.ts.map +1 -0
- package/dist/core/expressions/expression-proxy.js +227 -0
- package/dist/core/expressions/expression-proxy.js.map +1 -0
- package/dist/core/expressions/factory-integration.d.ts +132 -0
- package/dist/core/expressions/factory-integration.d.ts.map +1 -0
- package/dist/core/expressions/factory-integration.js +327 -0
- package/dist/core/expressions/factory-integration.js.map +1 -0
- package/dist/core/expressions/factory-pattern-handler.d.ts +88 -0
- package/dist/core/expressions/factory-pattern-handler.d.ts.map +1 -0
- package/dist/core/expressions/factory-pattern-handler.js +336 -0
- package/dist/core/expressions/factory-pattern-handler.js.map +1 -0
- package/dist/core/expressions/field-hydration-processor.d.ts +188 -0
- package/dist/core/expressions/field-hydration-processor.d.ts.map +1 -0
- package/dist/core/expressions/field-hydration-processor.js +562 -0
- package/dist/core/expressions/field-hydration-processor.js.map +1 -0
- package/dist/core/expressions/imperative-analyzer.d.ts +21 -0
- package/dist/core/expressions/imperative-analyzer.d.ts.map +1 -0
- package/dist/core/expressions/imperative-analyzer.js +457 -0
- package/dist/core/expressions/imperative-analyzer.js.map +1 -0
- package/dist/core/expressions/index.d.ts +54 -0
- package/dist/core/expressions/index.d.ts.map +1 -0
- package/dist/core/expressions/index.js +50 -0
- package/dist/core/expressions/index.js.map +1 -0
- package/dist/core/expressions/lazy-analysis.d.ts +1128 -0
- package/dist/core/expressions/lazy-analysis.d.ts.map +1 -0
- package/dist/core/expressions/lazy-analysis.js +2443 -0
- package/dist/core/expressions/lazy-analysis.js.map +1 -0
- package/dist/core/expressions/magic-assignable-analyzer.d.ts +123 -0
- package/dist/core/expressions/magic-assignable-analyzer.d.ts.map +1 -0
- package/dist/core/expressions/magic-assignable-analyzer.js +352 -0
- package/dist/core/expressions/magic-assignable-analyzer.js.map +1 -0
- package/dist/core/expressions/magic-proxy-analyzer.d.ts +206 -0
- package/dist/core/expressions/magic-proxy-analyzer.d.ts.map +1 -0
- package/dist/core/expressions/magic-proxy-analyzer.js +639 -0
- package/dist/core/expressions/magic-proxy-analyzer.js.map +1 -0
- package/dist/core/expressions/magic-proxy-detector.d.ts +154 -0
- package/dist/core/expressions/magic-proxy-detector.d.ts.map +1 -0
- package/dist/core/expressions/magic-proxy-detector.js +242 -0
- package/dist/core/expressions/magic-proxy-detector.js.map +1 -0
- package/dist/core/expressions/migration-helpers.d.ts +133 -0
- package/dist/core/expressions/migration-helpers.d.ts.map +1 -0
- package/dist/core/expressions/migration-helpers.js +443 -0
- package/dist/core/expressions/migration-helpers.js.map +1 -0
- package/dist/core/expressions/optionality-handler.d.ts +503 -0
- package/dist/core/expressions/optionality-handler.d.ts.map +1 -0
- package/dist/core/expressions/optionality-handler.js +1306 -0
- package/dist/core/expressions/optionality-handler.js.map +1 -0
- package/dist/core/expressions/readiness-integration.d.ts +119 -0
- package/dist/core/expressions/readiness-integration.d.ts.map +1 -0
- package/dist/core/expressions/readiness-integration.js +386 -0
- package/dist/core/expressions/readiness-integration.js.map +1 -0
- package/dist/core/expressions/resource-analyzer.d.ts +486 -0
- package/dist/core/expressions/resource-analyzer.d.ts.map +1 -0
- package/dist/core/expressions/resource-analyzer.js +1086 -0
- package/dist/core/expressions/resource-analyzer.js.map +1 -0
- package/dist/core/expressions/resource-validation.d.ts +187 -0
- package/dist/core/expressions/resource-validation.d.ts.map +1 -0
- package/dist/core/expressions/resource-validation.js +552 -0
- package/dist/core/expressions/resource-validation.js.map +1 -0
- package/dist/core/expressions/runtime-error-mapper.d.ts +138 -0
- package/dist/core/expressions/runtime-error-mapper.d.ts.map +1 -0
- package/dist/core/expressions/runtime-error-mapper.js +412 -0
- package/dist/core/expressions/runtime-error-mapper.js.map +1 -0
- package/dist/core/expressions/source-map.d.ts +168 -0
- package/dist/core/expressions/source-map.d.ts.map +1 -0
- package/dist/core/expressions/source-map.js +350 -0
- package/dist/core/expressions/source-map.js.map +1 -0
- package/dist/core/expressions/status-builder-analyzer.d.ts +353 -0
- package/dist/core/expressions/status-builder-analyzer.d.ts.map +1 -0
- package/dist/core/expressions/status-builder-analyzer.js +1311 -0
- package/dist/core/expressions/status-builder-analyzer.js.map +1 -0
- package/dist/core/expressions/type-inference.d.ts +184 -0
- package/dist/core/expressions/type-inference.d.ts.map +1 -0
- package/dist/core/expressions/type-inference.js +838 -0
- package/dist/core/expressions/type-inference.js.map +1 -0
- package/dist/core/expressions/type-safety.d.ts +203 -0
- package/dist/core/expressions/type-safety.d.ts.map +1 -0
- package/dist/core/expressions/type-safety.js +442 -0
- package/dist/core/expressions/type-safety.js.map +1 -0
- package/dist/core/expressions/types.d.ts +282 -0
- package/dist/core/expressions/types.d.ts.map +1 -0
- package/dist/core/expressions/types.js +8 -0
- package/dist/core/expressions/types.js.map +1 -0
- package/dist/core/kubernetes/client-provider.js +2 -2
- package/dist/core/kubernetes/client-provider.js.map +1 -1
- package/dist/core/references/cel.d.ts +13 -1
- package/dist/core/references/cel.d.ts.map +1 -1
- package/dist/core/references/cel.js +50 -0
- package/dist/core/references/cel.js.map +1 -1
- package/dist/core/references/schema-proxy.d.ts.map +1 -1
- package/dist/core/references/schema-proxy.js +13 -8
- package/dist/core/references/schema-proxy.js.map +1 -1
- package/dist/core/serialization/core.d.ts.map +1 -1
- package/dist/core/serialization/core.js +573 -9
- package/dist/core/serialization/core.js.map +1 -1
- package/dist/core/types/deployment.d.ts +7 -0
- package/dist/core/types/deployment.d.ts.map +1 -1
- package/dist/core/types/deployment.js +7 -0
- package/dist/core/types/deployment.js.map +1 -1
- package/dist/core/types/index.d.ts +1 -0
- package/dist/core/types/index.d.ts.map +1 -1
- package/dist/core/types/index.js.map +1 -1
- package/dist/core/validation/cel-validator.d.ts.map +1 -1
- package/dist/core/validation/cel-validator.js +4 -8
- package/dist/core/validation/cel-validator.js.map +1 -1
- package/dist/core.d.ts +1 -1
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +1 -1
- package/dist/core.js.map +1 -1
- package/dist/factories/helm/helm-release.d.ts.map +1 -1
- package/dist/factories/helm/helm-release.js +0 -5
- package/dist/factories/helm/helm-release.js.map +1 -1
- package/dist/factories/helm/types.d.ts +1 -1
- package/dist/factories/helm/types.d.ts.map +1 -1
- package/dist/factories/index.js +1 -0
- package/dist/factories/index.js.map +1 -1
- package/dist/factories/shared.d.ts.map +1 -1
- package/dist/factories/shared.js +21 -1
- package/dist/factories/shared.js.map +1 -1
- package/dist/factories/simple/index.d.ts +2 -2
- package/dist/factories/simple/index.d.ts.map +1 -1
- package/dist/factories/simple/workloads/deployment.d.ts +3 -3
- package/dist/factories/simple/workloads/deployment.d.ts.map +1 -1
- package/dist/factories/simple/workloads/deployment.js +37 -11
- package/dist/factories/simple/workloads/deployment.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/type-guards.d.ts +6 -0
- package/dist/utils/type-guards.d.ts.map +1 -1
- package/dist/utils/type-guards.js +25 -2
- package/dist/utils/type-guards.js.map +1 -1
- package/package.json +6 -1
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Factory Pattern Handler for JavaScript to CEL Expression Conversion
|
|
3
|
+
*
|
|
4
|
+
* This module provides different expression handling strategies based on the factory pattern:
|
|
5
|
+
* - DirectFactoryExpressionHandler: For direct deployment evaluation
|
|
6
|
+
* - KroFactoryExpressionHandler: For CEL conversion and Kro deployment
|
|
7
|
+
*
|
|
8
|
+
* The factory pattern determines how expressions containing KubernetesRef objects
|
|
9
|
+
* are processed and converted.
|
|
10
|
+
*/
|
|
11
|
+
import { ConversionError } from '../errors.js';
|
|
12
|
+
import { CEL_EXPRESSION_BRAND } from '../constants/brands.js';
|
|
13
|
+
/**
|
|
14
|
+
* Expression handler for direct deployment pattern
|
|
15
|
+
*
|
|
16
|
+
* In direct deployment, expressions are evaluated at deployment time
|
|
17
|
+
* by resolving KubernetesRef objects to actual values from deployed resources.
|
|
18
|
+
*/
|
|
19
|
+
export class DirectFactoryExpressionHandler {
|
|
20
|
+
getPatternType() {
|
|
21
|
+
return 'direct';
|
|
22
|
+
}
|
|
23
|
+
handleExpression(expression, context) {
|
|
24
|
+
try {
|
|
25
|
+
// For direct deployment, we still need to generate CEL expressions
|
|
26
|
+
// but they will be evaluated by the direct deployment engine
|
|
27
|
+
// rather than by the Kro controller
|
|
28
|
+
if (typeof expression === 'string') {
|
|
29
|
+
// Handle string expressions that may contain KubernetesRef references
|
|
30
|
+
return this.handleStringExpression(expression, context);
|
|
31
|
+
}
|
|
32
|
+
if (this.isKubernetesRef(expression)) {
|
|
33
|
+
// Direct KubernetesRef object
|
|
34
|
+
const celExpression = this.convertKubernetesRef(expression, context);
|
|
35
|
+
return {
|
|
36
|
+
valid: true,
|
|
37
|
+
celExpression,
|
|
38
|
+
dependencies: [expression],
|
|
39
|
+
sourceMap: [],
|
|
40
|
+
errors: [],
|
|
41
|
+
warnings: [],
|
|
42
|
+
requiresConversion: true
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
// For other types, check if they contain KubernetesRef objects
|
|
46
|
+
const dependencies = this.extractKubernetesRefs(expression);
|
|
47
|
+
if (dependencies.length === 0) {
|
|
48
|
+
// No KubernetesRef objects - no conversion needed
|
|
49
|
+
return {
|
|
50
|
+
valid: true,
|
|
51
|
+
celExpression: null,
|
|
52
|
+
dependencies: [],
|
|
53
|
+
sourceMap: [],
|
|
54
|
+
errors: [],
|
|
55
|
+
warnings: [],
|
|
56
|
+
requiresConversion: false
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
// Complex expression with KubernetesRef objects
|
|
60
|
+
return this.handleComplexExpression(expression, dependencies, context);
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
return {
|
|
64
|
+
valid: false,
|
|
65
|
+
celExpression: null,
|
|
66
|
+
dependencies: [],
|
|
67
|
+
sourceMap: [],
|
|
68
|
+
errors: [new ConversionError(`Direct factory expression handling failed: ${error instanceof Error ? error.message : String(error)}`, String(expression), 'javascript')],
|
|
69
|
+
warnings: [],
|
|
70
|
+
requiresConversion: true
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
convertKubernetesRef(ref, _context) {
|
|
75
|
+
// For direct deployment, generate CEL expressions that will be
|
|
76
|
+
// resolved by the direct deployment engine
|
|
77
|
+
if (ref.resourceId === '__schema__') {
|
|
78
|
+
// Schema references
|
|
79
|
+
return {
|
|
80
|
+
[CEL_EXPRESSION_BRAND]: true,
|
|
81
|
+
expression: `schema.${ref.fieldPath}`,
|
|
82
|
+
_type: ref._type
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
// Resource references
|
|
87
|
+
return {
|
|
88
|
+
[CEL_EXPRESSION_BRAND]: true,
|
|
89
|
+
expression: `resources.${ref.resourceId}.${ref.fieldPath}`,
|
|
90
|
+
_type: ref._type
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
handleStringExpression(expression, _context) {
|
|
95
|
+
// For direct deployment, string expressions are typically
|
|
96
|
+
// JavaScript expressions that need to be converted to CEL
|
|
97
|
+
// This would integrate with the main analyzer
|
|
98
|
+
// For now, return a placeholder result
|
|
99
|
+
return {
|
|
100
|
+
valid: true,
|
|
101
|
+
celExpression: {
|
|
102
|
+
[CEL_EXPRESSION_BRAND]: true,
|
|
103
|
+
expression: expression,
|
|
104
|
+
_type: undefined
|
|
105
|
+
},
|
|
106
|
+
dependencies: [],
|
|
107
|
+
sourceMap: [],
|
|
108
|
+
errors: [],
|
|
109
|
+
warnings: [],
|
|
110
|
+
requiresConversion: true
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
handleComplexExpression(_expression, dependencies, _context) {
|
|
114
|
+
// Handle complex expressions containing KubernetesRef objects
|
|
115
|
+
// This would involve analyzing the structure and converting appropriately
|
|
116
|
+
return {
|
|
117
|
+
valid: true,
|
|
118
|
+
celExpression: {
|
|
119
|
+
[CEL_EXPRESSION_BRAND]: true,
|
|
120
|
+
expression: `/* Complex expression with ${dependencies.length} dependencies */`,
|
|
121
|
+
_type: undefined
|
|
122
|
+
},
|
|
123
|
+
dependencies,
|
|
124
|
+
sourceMap: [],
|
|
125
|
+
errors: [],
|
|
126
|
+
warnings: [],
|
|
127
|
+
requiresConversion: true
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
isKubernetesRef(value) {
|
|
131
|
+
return value && typeof value === 'object' &&
|
|
132
|
+
typeof value.resourceId === 'string' &&
|
|
133
|
+
typeof value.fieldPath === 'string';
|
|
134
|
+
}
|
|
135
|
+
extractKubernetesRefs(value) {
|
|
136
|
+
const refs = [];
|
|
137
|
+
if (this.isKubernetesRef(value)) {
|
|
138
|
+
refs.push(value);
|
|
139
|
+
}
|
|
140
|
+
else if (Array.isArray(value)) {
|
|
141
|
+
for (const item of value) {
|
|
142
|
+
refs.push(...this.extractKubernetesRefs(item));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
else if (value && typeof value === 'object') {
|
|
146
|
+
for (const key in value) {
|
|
147
|
+
if (Object.hasOwn(value, key)) {
|
|
148
|
+
refs.push(...this.extractKubernetesRefs(value[key]));
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return refs;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Expression handler for Kro deployment pattern
|
|
157
|
+
*
|
|
158
|
+
* In Kro deployment, expressions are converted to CEL and evaluated
|
|
159
|
+
* by the Kro controller at runtime.
|
|
160
|
+
*/
|
|
161
|
+
export class KroFactoryExpressionHandler {
|
|
162
|
+
getPatternType() {
|
|
163
|
+
return 'kro';
|
|
164
|
+
}
|
|
165
|
+
handleExpression(expression, context) {
|
|
166
|
+
try {
|
|
167
|
+
// For Kro deployment, we need to generate CEL expressions
|
|
168
|
+
// that will be evaluated by the Kro controller
|
|
169
|
+
if (typeof expression === 'string') {
|
|
170
|
+
// Handle string expressions that may contain KubernetesRef references
|
|
171
|
+
return this.handleStringExpression(expression, context);
|
|
172
|
+
}
|
|
173
|
+
if (this.isKubernetesRef(expression)) {
|
|
174
|
+
// Direct KubernetesRef object
|
|
175
|
+
const celExpression = this.convertKubernetesRef(expression, context);
|
|
176
|
+
return {
|
|
177
|
+
valid: true,
|
|
178
|
+
celExpression,
|
|
179
|
+
dependencies: [expression],
|
|
180
|
+
sourceMap: [],
|
|
181
|
+
errors: [],
|
|
182
|
+
warnings: [],
|
|
183
|
+
requiresConversion: true
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
// For other types, check if they contain KubernetesRef objects
|
|
187
|
+
const dependencies = this.extractKubernetesRefs(expression);
|
|
188
|
+
if (dependencies.length === 0) {
|
|
189
|
+
// No KubernetesRef objects - no conversion needed
|
|
190
|
+
return {
|
|
191
|
+
valid: true,
|
|
192
|
+
celExpression: null,
|
|
193
|
+
dependencies: [],
|
|
194
|
+
sourceMap: [],
|
|
195
|
+
errors: [],
|
|
196
|
+
warnings: [],
|
|
197
|
+
requiresConversion: false
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
// Complex expression with KubernetesRef objects
|
|
201
|
+
return this.handleComplexExpression(expression, dependencies, context);
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
return {
|
|
205
|
+
valid: false,
|
|
206
|
+
celExpression: null,
|
|
207
|
+
dependencies: [],
|
|
208
|
+
sourceMap: [],
|
|
209
|
+
errors: [new ConversionError(`Kro factory expression handling failed: ${error instanceof Error ? error.message : String(error)}`, String(expression), 'javascript')],
|
|
210
|
+
warnings: [],
|
|
211
|
+
requiresConversion: true
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
convertKubernetesRef(ref, _context) {
|
|
216
|
+
// For Kro deployment, generate CEL expressions that will be
|
|
217
|
+
// evaluated by the Kro controller
|
|
218
|
+
if (ref.resourceId === '__schema__') {
|
|
219
|
+
// Schema references
|
|
220
|
+
return {
|
|
221
|
+
[CEL_EXPRESSION_BRAND]: true,
|
|
222
|
+
expression: `schema.${ref.fieldPath}`,
|
|
223
|
+
_type: ref._type
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
// Resource references
|
|
228
|
+
return {
|
|
229
|
+
[CEL_EXPRESSION_BRAND]: true,
|
|
230
|
+
expression: `resources.${ref.resourceId}.${ref.fieldPath}`,
|
|
231
|
+
_type: ref._type
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
handleStringExpression(expression, _context) {
|
|
236
|
+
// For Kro deployment, string expressions need to be converted
|
|
237
|
+
// to CEL expressions that the Kro controller can evaluate
|
|
238
|
+
// For now, return a placeholder result
|
|
239
|
+
return {
|
|
240
|
+
valid: true,
|
|
241
|
+
celExpression: {
|
|
242
|
+
[CEL_EXPRESSION_BRAND]: true,
|
|
243
|
+
expression: expression,
|
|
244
|
+
_type: undefined
|
|
245
|
+
},
|
|
246
|
+
dependencies: [],
|
|
247
|
+
sourceMap: [],
|
|
248
|
+
errors: [],
|
|
249
|
+
warnings: [],
|
|
250
|
+
requiresConversion: true
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
handleComplexExpression(_expression, dependencies, _context) {
|
|
254
|
+
// Handle complex expressions containing KubernetesRef objects
|
|
255
|
+
// For Kro deployment, these need to be converted to CEL expressions
|
|
256
|
+
return {
|
|
257
|
+
valid: true,
|
|
258
|
+
celExpression: {
|
|
259
|
+
[CEL_EXPRESSION_BRAND]: true,
|
|
260
|
+
expression: `/* Complex Kro expression with ${dependencies.length} dependencies */`,
|
|
261
|
+
_type: undefined
|
|
262
|
+
},
|
|
263
|
+
dependencies,
|
|
264
|
+
sourceMap: [],
|
|
265
|
+
errors: [],
|
|
266
|
+
warnings: [],
|
|
267
|
+
requiresConversion: true
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
isKubernetesRef(value) {
|
|
271
|
+
return value && typeof value === 'object' &&
|
|
272
|
+
typeof value.resourceId === 'string' &&
|
|
273
|
+
typeof value.fieldPath === 'string';
|
|
274
|
+
}
|
|
275
|
+
extractKubernetesRefs(value) {
|
|
276
|
+
const refs = [];
|
|
277
|
+
if (this.isKubernetesRef(value)) {
|
|
278
|
+
refs.push(value);
|
|
279
|
+
}
|
|
280
|
+
else if (Array.isArray(value)) {
|
|
281
|
+
for (const item of value) {
|
|
282
|
+
refs.push(...this.extractKubernetesRefs(item));
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
else if (value && typeof value === 'object') {
|
|
286
|
+
for (const key in value) {
|
|
287
|
+
if (Object.hasOwn(value, key)) {
|
|
288
|
+
refs.push(...this.extractKubernetesRefs(value[key]));
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return refs;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Factory for creating appropriate expression handlers based on factory pattern
|
|
297
|
+
*/
|
|
298
|
+
export class FactoryPatternHandlerFactory {
|
|
299
|
+
/**
|
|
300
|
+
* Create an expression handler for the specified factory pattern
|
|
301
|
+
*/
|
|
302
|
+
static createHandler(patternType) {
|
|
303
|
+
switch (patternType) {
|
|
304
|
+
case 'direct':
|
|
305
|
+
return new DirectFactoryExpressionHandler();
|
|
306
|
+
case 'kro':
|
|
307
|
+
return new KroFactoryExpressionHandler();
|
|
308
|
+
default:
|
|
309
|
+
throw new Error(`Unsupported factory pattern type: ${patternType}`);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Detect factory pattern from context
|
|
314
|
+
*/
|
|
315
|
+
static detectFactoryPattern(context) {
|
|
316
|
+
return context.factoryType;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Create handler based on analysis context
|
|
320
|
+
*/
|
|
321
|
+
static createHandlerFromContext(context) {
|
|
322
|
+
const patternType = FactoryPatternHandlerFactory.detectFactoryPattern(context);
|
|
323
|
+
return FactoryPatternHandlerFactory.createHandler(patternType);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Main factory pattern integration point
|
|
328
|
+
*
|
|
329
|
+
* This function provides the main integration point for factory pattern
|
|
330
|
+
* aware expression handling.
|
|
331
|
+
*/
|
|
332
|
+
export function handleExpressionWithFactoryPattern(expression, context) {
|
|
333
|
+
const handler = FactoryPatternHandlerFactory.createHandlerFromContext(context);
|
|
334
|
+
return handler.handleExpression(expression, context);
|
|
335
|
+
}
|
|
336
|
+
//# sourceMappingURL=factory-pattern-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory-pattern-handler.js","sourceRoot":"","sources":["../../../src/core/expressions/factory-pattern-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAkC9D;;;;;GAKG;AACH,MAAM,OAAO,8BAA8B;IAEzC,cAAc;QACZ,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,gBAAgB,CACd,UAAe,EACf,OAAwB;QAExB,IAAI,CAAC;YACH,mEAAmE;YACnE,6DAA6D;YAC7D,oCAAoC;YAEpC,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;gBACnC,sEAAsE;gBACtE,OAAO,IAAI,CAAC,sBAAsB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;YAC1D,CAAC;YAED,IAAI,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,EAAE,CAAC;gBACrC,8BAA8B;gBAC9B,M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,aAAa,CAAC,WAA+B;QAClD,QAAQ,WAAW,EAAE,CAAC;YACpB,KAAK,QAAQ;gBACX,OAAO,IAAI,8BAA8B,EAAE,CAAC;YAC9C,KAAK,KAAK;gBACR,OAAO,IAAI,2BAA2B,EAAE,CAAC;YAC3C;gBACE,MAAM,IAAI,KAAK,CAAC,qCAAqC,WAAW,EAAE,CAAC,CAAC;QACxE,CAAC;IACH,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,oBAAoB,CAAC,OAAwB;QAClD,OAAO,OAAO,CAAC,WAAW,CAAC;IAC7B,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,wBAAwB,CAAC,OAAwB;QACtD,MAAM,WAAW,GAAG,4BAA4B,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAC/E,OAAO,4BAA4B,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;IACjE,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,UAAU,kCAAkC,CAChD,UAAe,EACf,OAAwB;IAExB,MAAM,OAAO,GAAG,4BAA4B,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC;IAC/E,OAAO,OAAO,CAAC,gBAAgB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;AACvD,CAAC"}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Field Hydration Integration for JavaScript to CEL Expression Conversion
|
|
3
|
+
*
|
|
4
|
+
* This module provides integration between the JavaScript to CEL expression conversion system
|
|
5
|
+
* and TypeKro's field hydration strategy. It processes status expressions containing KubernetesRef
|
|
6
|
+
* objects and tracks dependencies to ensure proper hydration ordering.
|
|
7
|
+
*
|
|
8
|
+
* Key Features:
|
|
9
|
+
* - Uses AST parsing to analyze status builder functions
|
|
10
|
+
* - Processes status builder expressions with KubernetesRef dependency tracking
|
|
11
|
+
* - Extracts dependencies from KubernetesRef objects in expressions
|
|
12
|
+
* - Integrates with existing field hydration strategy for proper ordering
|
|
13
|
+
* - Handles both direct and Kro factory patterns
|
|
14
|
+
* - Provides dependency analysis for status field population
|
|
15
|
+
*/
|
|
16
|
+
import type { CelExpression, KubernetesRef } from '../types/common.js';
|
|
17
|
+
import type { Enhanced } from '../types/kubernetes.js';
|
|
18
|
+
import type { SchemaProxy } from '../types/serialization.js';
|
|
19
|
+
import { ConversionError } from '../errors.js';
|
|
20
|
+
import type { DeploymentPlan } from '../dependencies/resolver.js';
|
|
21
|
+
import { JavaScriptToCelAnalyzer, type CelConversionResult } from './analyzer.js';
|
|
22
|
+
import { type SourceMapEntry } from './source-map.js';
|
|
23
|
+
/**
|
|
24
|
+
* Status builder function type for analysis
|
|
25
|
+
*/
|
|
26
|
+
export type StatusBuilderFunction<TSpec extends Record<string, any> = any, TStatus = any> = (schema: SchemaProxy<TSpec, any>, resources: Record<string, Enhanced<any, any>>) => TStatus;
|
|
27
|
+
/**
|
|
28
|
+
* Resource reference for dependency tracking
|
|
29
|
+
*/
|
|
30
|
+
export interface ResourceReference {
|
|
31
|
+
/** Resource ID being referenced */
|
|
32
|
+
resourceId: string;
|
|
33
|
+
/** Type of reference (resource or schema) */
|
|
34
|
+
type: 'resource' | 'schema';
|
|
35
|
+
/** Field path being accessed */
|
|
36
|
+
fieldPath?: string;
|
|
37
|
+
/** Whether this reference is optional (uses optional chaining) */
|
|
38
|
+
optional?: boolean;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Field hydration strategy interface
|
|
42
|
+
*/
|
|
43
|
+
export interface FieldHydrationStrategy {
|
|
44
|
+
/**
|
|
45
|
+
* Calculate the order in which status fields should be hydrated based on dependencies
|
|
46
|
+
*/
|
|
47
|
+
calculateHydrationOrder(dependencies: Map<string, ResourceReference[]>): string[];
|
|
48
|
+
/**
|
|
49
|
+
* Determine if a field can be hydrated in parallel with others
|
|
50
|
+
*/
|
|
51
|
+
canHydrateInParallel(fieldName: string, dependencies: ResourceReference[]): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Get the priority of a field for hydration ordering
|
|
54
|
+
*/
|
|
55
|
+
getFieldPriority(fieldName: string, dependencies: ResourceReference[]): number;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Default field hydration strategy implementation
|
|
59
|
+
*/
|
|
60
|
+
export declare class DefaultFieldHydrationStrategy implements FieldHydrationStrategy {
|
|
61
|
+
calculateHydrationOrder(dependencies: Map<string, ResourceReference[]>): string[];
|
|
62
|
+
canHydrateInParallel(_fieldName: string, dependencies: ResourceReference[]): boolean;
|
|
63
|
+
getFieldPriority(_fieldName: string, dependencies: ResourceReference[]): number;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Result of processing status expressions
|
|
67
|
+
*/
|
|
68
|
+
export interface ProcessedStatusBuilder {
|
|
69
|
+
/** Processed status field mappings with CEL expressions */
|
|
70
|
+
statusMappings: Record<string, CelExpression>;
|
|
71
|
+
/** Recommended hydration order for status fields */
|
|
72
|
+
hydrationOrder: string[];
|
|
73
|
+
/** Dependencies for each status field */
|
|
74
|
+
dependencies: Map<string, ResourceReference[]>;
|
|
75
|
+
/** Source mapping entries for debugging */
|
|
76
|
+
sourceMap: SourceMapEntry[];
|
|
77
|
+
/** Processing errors encountered */
|
|
78
|
+
errors: ConversionError[];
|
|
79
|
+
/** Whether processing was successful */
|
|
80
|
+
valid: boolean;
|
|
81
|
+
/** Analysis results for each field */
|
|
82
|
+
fieldAnalysis: Map<string, CelConversionResult>;
|
|
83
|
+
/** Resource references found across all fields */
|
|
84
|
+
allResourceReferences: ResourceReference[];
|
|
85
|
+
/** Schema references found across all fields */
|
|
86
|
+
allSchemaReferences: ResourceReference[];
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Options for field hydration expression processing
|
|
90
|
+
*/
|
|
91
|
+
export interface FieldHydrationProcessingOptions {
|
|
92
|
+
/** Field hydration strategy to use */
|
|
93
|
+
hydrationStrategy?: FieldHydrationStrategy;
|
|
94
|
+
/** Whether to perform deep analysis of expressions */
|
|
95
|
+
deepAnalysis?: boolean;
|
|
96
|
+
/** Whether to validate resource references */
|
|
97
|
+
validateReferences?: boolean;
|
|
98
|
+
/** Whether to include source mapping */
|
|
99
|
+
includeSourceMapping?: boolean;
|
|
100
|
+
/** Maximum depth for expression analysis */
|
|
101
|
+
maxAnalysisDepth?: number;
|
|
102
|
+
/** Factory type for CEL generation strategy */
|
|
103
|
+
factoryType?: 'direct' | 'kro';
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Field Hydration Expression Processor
|
|
107
|
+
*
|
|
108
|
+
* Processes status builder functions to extract KubernetesRef dependencies
|
|
109
|
+
* and integrate with TypeKro's field hydration strategy.
|
|
110
|
+
*/
|
|
111
|
+
export declare class FieldHydrationExpressionProcessor {
|
|
112
|
+
private expressionAnalyzer;
|
|
113
|
+
private magicProxyAnalyzer;
|
|
114
|
+
private dependencyResolver;
|
|
115
|
+
private options;
|
|
116
|
+
private logger;
|
|
117
|
+
constructor(expressionAnalyzer?: JavaScriptToCelAnalyzer, options?: FieldHydrationProcessingOptions);
|
|
118
|
+
/**
|
|
119
|
+
* Process status expressions with KubernetesRef dependency tracking
|
|
120
|
+
*
|
|
121
|
+
* This is the main method that analyzes a status builder function and extracts
|
|
122
|
+
* dependencies for proper field hydration ordering.
|
|
123
|
+
*/
|
|
124
|
+
processStatusExpressions<TSpec extends Record<string, any>, TStatus>(statusBuilder: StatusBuilderFunction<TSpec, TStatus>, resources: Record<string, Enhanced<any, any>>, schemaProxy?: SchemaProxy<TSpec, any>): ProcessedStatusBuilder;
|
|
125
|
+
/**
|
|
126
|
+
* Extract dependencies from KubernetesRef objects in expressions
|
|
127
|
+
*
|
|
128
|
+
* This method analyzes the KubernetesRef objects found in expressions and
|
|
129
|
+
* converts them to ResourceReference objects for dependency tracking.
|
|
130
|
+
*/
|
|
131
|
+
extractDependenciesFromKubernetesRefs(kubernetesRefs: KubernetesRef<any>[]): ResourceReference[];
|
|
132
|
+
/**
|
|
133
|
+
* Integrate with existing field hydration strategy
|
|
134
|
+
*
|
|
135
|
+
* This method provides integration points with TypeKro's existing field hydration
|
|
136
|
+
* system by providing dependency information and hydration ordering.
|
|
137
|
+
*/
|
|
138
|
+
integrateWithFieldHydrationStrategy(processedStatus: ProcessedStatusBuilder, existingStrategy?: FieldHydrationStrategy): {
|
|
139
|
+
enhancedStrategy: FieldHydrationStrategy;
|
|
140
|
+
hydrationPlan: DeploymentPlan;
|
|
141
|
+
parallelizableFields: string[][];
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* Strip TypeScript syntax that esprima cannot parse
|
|
145
|
+
*/
|
|
146
|
+
private stripTypeScriptSyntax;
|
|
147
|
+
/**
|
|
148
|
+
* Extract field expressions from a status builder function using AST parsing
|
|
149
|
+
*/
|
|
150
|
+
private extractFieldExpressions;
|
|
151
|
+
/**
|
|
152
|
+
* Find the return statement or arrow function body in a function AST
|
|
153
|
+
*/
|
|
154
|
+
private findReturnStatement;
|
|
155
|
+
/**
|
|
156
|
+
* Extract field expressions from a return statement or arrow function body
|
|
157
|
+
*/
|
|
158
|
+
private extractFieldExpressionsFromReturnStatement;
|
|
159
|
+
/**
|
|
160
|
+
* Create mock resources for fallback field extraction
|
|
161
|
+
*/
|
|
162
|
+
private createMockResources;
|
|
163
|
+
/**
|
|
164
|
+
* Analyze a single field expression for KubernetesRef objects
|
|
165
|
+
*/
|
|
166
|
+
private analyzeFieldExpression;
|
|
167
|
+
/**
|
|
168
|
+
* Extract KubernetesRef objects from a value (recursively)
|
|
169
|
+
*/
|
|
170
|
+
private extractKubernetesRefsFromValue;
|
|
171
|
+
/**
|
|
172
|
+
* Extract dependencies from analysis result
|
|
173
|
+
*/
|
|
174
|
+
private extractDependenciesFromAnalysis;
|
|
175
|
+
/**
|
|
176
|
+
* Categorize all references into resource and schema references
|
|
177
|
+
*/
|
|
178
|
+
private categorizeAllReferences;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Convenience function to process status expressions
|
|
182
|
+
*/
|
|
183
|
+
export declare function processStatusExpressions<TSpec extends Record<string, any>, TStatus>(statusBuilder: StatusBuilderFunction<TSpec, TStatus>, resources: Record<string, Enhanced<any, any>>, schemaProxy?: SchemaProxy<TSpec, any>, options?: FieldHydrationProcessingOptions): ProcessedStatusBuilder;
|
|
184
|
+
/**
|
|
185
|
+
* Convenience function to extract dependencies from KubernetesRef objects
|
|
186
|
+
*/
|
|
187
|
+
export declare function extractDependenciesFromKubernetesRefs(kubernetesRefs: KubernetesRef<any>[]): ResourceReference[];
|
|
188
|
+
//# sourceMappingURL=field-hydration-processor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"field-hydration-processor.d.ts","sourceRoot":"","sources":["../../../src/core/expressions/field-hydration-processor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAMH,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAI/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,uBAAuB,EAAwB,KAAK,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAExG,OAAO,EAAoB,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAExE;;GAEG;AACH,MAAM,MAAM,qBAAqB,CAAC,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,CAC1F,MAAM,EAAE,WAAW,CAAC,KAAK,EAAE,GAAG,CAAC,EAC/B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,KAC1C,OAAO,CAAC;AAE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