Class DslParser
FlowDefinition parser (v4 §4, §11).
JSON DSL → FlowDefinition 解析器(v4 §4 / §11)。
This parser is responsible for structural conversion only:
- Enforce hard size quota (default 256 KiB; tunable via
opencode.base.flow.dsl-max-bytes). - Validate
schemaVersion == "1.0", else throwFlowErrorCode.DSL_UNSUPPORTED_SCHEMA_VERSION. - Materialize raw JSON into model records (
Step,Transition,Assignee). Per-record validation (length, mode/strategy compatibility) is enforced inside the records. - Cache parsed
FlowDefinitionby exact DSL string in a size-bounded LRU (default 256; tunable viaopencode.base.flow.dsl-cache-size).
Out of scope for this parser: reference completeness
(every transition.from/to exists in steps[].id) and other
semantic / quota rules — those are owned by the sibling
DslValidator class.
本解析器只负责结构层转换:尺寸配额、schemaVersion 检查、raw DSL →
领域 record 转换、按字符串 LRU 缓存。引用完整性 / 配额 / 嵌套深度等校验由
DslValidator 负责。
Both maxBytes and cacheCapacity are read once at
construction from System.getProperty(String) and frozen as
instance fields (v4 D22 — avoid System.getProperty drift at runtime).
maxBytes 与 cacheCapacity 在构造时一次性读取系统属性并固化为
实例 final 字段(v4 D22:避免运行期 System.getProperty 漂移)。
- Since:
- JDK 25, opencode-base-flow V1.0.5
- Author:
- Leon Soo
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault LRU cache capacity.static final intDefault max DSL size in bytes (UTF-16 chars; conservative bound).static final PatternAllowed characters inflowKey— starts with a letter, body limited to alphanumerics / underscore / hyphen / dot.static final intHard cap onflowKeylength (matches typical DB index limit). flowKey 长度上限(适配常见 DB 索引限制)。static final intHard cap onnamelength. name 字段长度上限。static final StringSystem property for parse cache capacity; default 256.static final StringSystem property for max DSL byte size; default 256 KiB.static final StringCurrently supported DSL schemaVersion. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintReturns the frozen cache capacity.intReturns the size of the parse cache (mainly for tests).voidClears the parse cache.intmaxBytes()Returns the frozen max-bytes limit.Parses the given DSL JSON string into aFlowDefinition.
-
Field Details
-
SUPPORTED_SCHEMA_VERSION
Currently supported DSL schemaVersion.- See Also:
-
PROP_MAX_BYTES
System property for max DSL byte size; default 256 KiB.- See Also:
-
DEFAULT_MAX_BYTES
public static final int DEFAULT_MAX_BYTESDefault max DSL size in bytes (UTF-16 chars; conservative bound).- See Also:
-
PROP_CACHE_SIZE
System property for parse cache capacity; default 256.- See Also:
-
DEFAULT_CACHE_SIZE
public static final int DEFAULT_CACHE_SIZEDefault LRU cache capacity.- See Also:
-
MAX_FLOW_KEY_LEN
public static final int MAX_FLOW_KEY_LENHard cap onflowKeylength (matches typical DB index limit). flowKey 长度上限(适配常见 DB 索引限制)。- See Also:
-
MAX_NAME_LEN
public static final int MAX_NAME_LENHard cap onnamelength. name 字段长度上限。- See Also:
-
FLOW_KEY_PATTERN
Allowed characters inflowKey— starts with a letter, body limited to alphanumerics / underscore / hyphen / dot. Prevents log forging, path-traversal and metrics-tag injection via flowKey. flowKey 允许字符集;防止借 flowKey 做日志投毒、路径穿越、指标标签注入。
-
-
Constructor Details
-
DslParser
public DslParser()Constructs a parser using the default JSON provider. 使用默认 JSON 提供者构造 parser。- Since:
- JDK 25, opencode-base-flow V1.0.5
-
DslParser
public DslParser(int maxBytes, int cacheCapacity) Constructs a parser with explicit limits (mainly for tests). 显式指定上限的构造(主要供测试使用)。- Parameters:
maxBytes- max DSL string length — 解析前长度上限cacheCapacity- LRU cache size (≥ 1) — LRU 容量(≥ 1)- Since:
- JDK 25, opencode-base-flow V1.0.5
-
-
Method Details
-
parse
Parses the given DSL JSON string into aFlowDefinition. 把给定的 DSL JSON 解析为FlowDefinition。The returned definition has an empty
id(the service layer fills it after validation succeeds —DslValidatorowns reference-completeness checks).返回值的
id留空(由 service 层在校验通过后填充;DslValidator负责引用完整性校验)。- Parameters:
dslJson- DSL JSON string — DSL JSON 字符串- Returns:
- parsed flow definition — 解析后的流程定义
- Throws:
DslParseException- on quota, schema-version or structural errors- Since:
- JDK 25, opencode-base-flow V1.0.5
-
cacheSize
public int cacheSize()Returns the size of the parse cache (mainly for tests). 返回解析缓存当前大小(主要供测试使用)。- Returns:
- current entry count — 当前条目数
- Since:
- JDK 25, opencode-base-flow V1.0.5
-
clearCache
public void clearCache()Clears the parse cache. 清空解析缓存。- Since:
- JDK 25, opencode-base-flow V1.0.5
-
maxBytes
public int maxBytes()Returns the frozen max-bytes limit. 返回固化后的字节上限。- Returns:
- max bytes — 上限
- Since:
- JDK 25, opencode-base-flow V1.0.5
-
cacheCapacity
public int cacheCapacity()Returns the frozen cache capacity. 返回固化后的缓存容量。- Returns:
- cache capacity — 容量
- Since:
- JDK 25, opencode-base-flow V1.0.5
-