feat: sync deployed v1.0.0-rc.38-custom.42
Sync production source including routing, billing, Astra detection and public uptime. Update custom build instructions and license packaging.
This commit is contained in:
1 parent
aa6c3f50f4
commit
ceddfd3d6b
828 files changed
+122253
-13702
No files matched your search
+53
-28
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/expr-lang/expr"
|
||||
"github.com/expr-lang/expr/ast"
|
||||
"github.com/expr-lang/expr/parser"
|
||||
"github.com/expr-lang/expr/vm"
|
||||
)
|
||||
|
||||
@@ -114,6 +115,7 @@ type cachedEntry struct {
|
||||
usedUsageKeys map[string]bool
|
||||
requestRules []RequestRuleTrace
|
||||
version int
|
||||
fixedPricing bool
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -123,33 +125,36 @@ var (
|
||||
|
||||
// compileEnvPrototypeV1 is the v1 type-checking prototype used at compile time.
|
||||
var compileEnvPrototypeV1 = map[string]any{
|
||||
"p": float64(0),
|
||||
"c": float64(0),
|
||||
"len": float64(0),
|
||||
"cr": float64(0),
|
||||
"cc": float64(0),
|
||||
"cc1h": float64(0),
|
||||
"img": float64(0),
|
||||
"img_o": float64(0),
|
||||
"ai": float64(0),
|
||||
"ao": float64(0),
|
||||
"tier": func(string, float64) float64 { return 0 },
|
||||
"_trace": func(int, bool, float64) float64 { return 1 },
|
||||
"_trace_int": func(int, bool, int) int { return 1 },
|
||||
"header": func(string) string { return "" },
|
||||
"param": func(string) any { return nil },
|
||||
"u": func(string) any { return nil },
|
||||
"has": func(any, string) bool { return false },
|
||||
"hour": func(string) int { return 0 },
|
||||
"minute": func(string) int { return 0 },
|
||||
"weekday": func(string) int { return 0 },
|
||||
"month": func(string) int { return 0 },
|
||||
"day": func(string) int { return 0 },
|
||||
"max": math.Max,
|
||||
"min": math.Min,
|
||||
"abs": math.Abs,
|
||||
"ceil": math.Ceil,
|
||||
"floor": math.Floor,
|
||||
"image_count": float64(1),
|
||||
"p": float64(0),
|
||||
"c": float64(0),
|
||||
"len": float64(0),
|
||||
"cr": float64(0),
|
||||
"cc": float64(0),
|
||||
"cc1h": float64(0),
|
||||
"img": float64(0),
|
||||
"img_cr": float64(0),
|
||||
"img_o": float64(0),
|
||||
"ai": float64(0),
|
||||
"ao": float64(0),
|
||||
"tier": func(string, float64) float64 { return 0 },
|
||||
"fixed": func(float64) float64 { return 0 },
|
||||
"_trace": func(int, bool, float64) float64 { return 1 },
|
||||
"_trace_int": func(int, bool, int) int { return 1 },
|
||||
"header": func(string) string { return "" },
|
||||
"param": func(string) any { return nil },
|
||||
"u": func(string) any { return nil },
|
||||
"has": func(any, string) bool { return false },
|
||||
"hour": func(string) int { return 0 },
|
||||
"minute": func(string) int { return 0 },
|
||||
"weekday": func(string) int { return 0 },
|
||||
"month": func(string) int { return 0 },
|
||||
"day": func(string) int { return 0 },
|
||||
"max": math.Max,
|
||||
"min": math.Min,
|
||||
"abs": math.Abs,
|
||||
"ceil": math.Ceil,
|
||||
"floor": math.Floor,
|
||||
}
|
||||
|
||||
func getCompileEnv(version int) map[string]any {
|
||||
@@ -188,6 +193,21 @@ func compileEntryFromCacheByHash(exprStr, hash string) (*cachedEntry, error) {
|
||||
cacheMu.RUnlock()
|
||||
|
||||
version, body := ParseExprVersion(exprStr)
|
||||
// Validate before optimization so unreachable fixed-price branches cannot
|
||||
// bypass validation or a host's unsupported-protocol checks.
|
||||
tree, err := parser.Parse(body)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("expr compile error: %w", err)
|
||||
}
|
||||
fixedPricing := ast.Find(tree.Node, func(node ast.Node) bool {
|
||||
identifier, ok := node.(*ast.IdentifierNode)
|
||||
return ok && identifier.Value == "fixed"
|
||||
}) != nil
|
||||
if fixedPricing {
|
||||
if err := validateFixedPricingTree(tree.Node); err != nil {
|
||||
return nil, fmt.Errorf("expr compile error: %w", err)
|
||||
}
|
||||
}
|
||||
patcher := &requestRulePatcher{}
|
||||
prog, err := expr.Compile(body, expr.Env(getCompileEnv(version)), expr.Patch(patcher), expr.AsFloat64())
|
||||
if patcher.restrictedIdentifier != "" {
|
||||
@@ -203,6 +223,7 @@ func compileEntryFromCacheByHash(exprStr, hash string) (*cachedEntry, error) {
|
||||
usedUsageKeys: extractUsedUsageKeys(prog),
|
||||
requestRules: patcher.requestRules,
|
||||
version: version,
|
||||
fixedPricing: fixedPricing,
|
||||
}
|
||||
cacheMu.Lock()
|
||||
if len(cache) >= maxCacheSize {
|
||||
@@ -271,10 +292,14 @@ func extractUsedUsageKeys(prog *vm.Program) map[string]bool {
|
||||
// UsedVars returns the set of identifier names referenced by an expression.
|
||||
// The result is cached alongside the compiled program. Returns nil for empty input.
|
||||
func UsedVars(exprStr string) map[string]bool {
|
||||
return UsedVarsByHash(exprStr, ExprHashString(exprStr))
|
||||
}
|
||||
|
||||
// UsedVarsByHash reuses the digest captured by the host's billing snapshot.
|
||||
func UsedVarsByHash(exprStr, hash string) map[string]bool {
|
||||
if exprStr == "" {
|
||||
return nil
|
||||
}
|
||||
hash := ExprHashString(exprStr)
|
||||
cacheMu.RLock()
|
||||
if entry, ok := cache[hash]; ok {
|
||||
cacheMu.RUnlock()
|
||||
|
||||
Reference in new issue
Block a user