packages/engine/planTemplate
plan templates: a NAMED, REUSABLE, PARAMETERISED plan.
Engine, v0.9. Source: packages/engine/planTemplate.mjs.
Classes#
TemplateError#
Defined in: packages/engine/planTemplate.mjs:56
A refusal with a stable, named code and structured errors.
Extends#
Error
Constructors#
Constructor
new TemplateError(
code,message,errors):TemplateError
Defined in: packages/engine/planTemplate.mjs:57
Parameters
code
any
message
any
errors
any
Returns
Overrides
Error.constructor
Properties#
code
code:
any
Defined in: packages/engine/planTemplate.mjs:60
errors
errors:
any
Defined in: packages/engine/planTemplate.mjs:61
name
name:
string
Defined in: packages/engine/planTemplate.mjs:59
Inherited from
Error.name
Variables#
PARAM_TYPES#
constPARAM_TYPES: readonlystring[]
Defined in: packages/engine/planTemplate.mjs:34
TEMPLATE_ERROR_CODES#
constTEMPLATE_ERROR_CODES:Readonly<{PARAM_ENUM:"PARAM_ENUM";PARAM_INVALID:"PARAM_INVALID";PARAM_MISSING:"PARAM_MISSING";PARAM_TYPE:"PARAM_TYPE";PARAM_UNKNOWN:"PARAM_UNKNOWN";TEMPLATE_DUPLICATE:"TEMPLATE_DUPLICATE";TEMPLATE_EXAMPLE_INVALID:"TEMPLATE_EXAMPLE_INVALID";TEMPLATE_FLOW_UNKNOWN:"TEMPLATE_FLOW_UNKNOWN";TEMPLATE_INVALID:"TEMPLATE_INVALID";TEMPLATE_NAME_INVALID:"TEMPLATE_NAME_INVALID";TEMPLATE_NOT_FOUND:"TEMPLATE_NOT_FOUND";TEMPLATE_NOT_OBJECT:"TEMPLATE_NOT_OBJECT";TEMPLATE_PARAM_INVALID:"TEMPLATE_PARAM_INVALID";TEMPLATE_PARAM_UNDEFINED:"TEMPLATE_PARAM_UNDEFINED";TEMPLATE_PLACEHOLDER_FORBIDDEN:"TEMPLATE_PLACEHOLDER_FORBIDDEN";TEMPLATE_VERSION_INVALID:"TEMPLATE_VERSION_INVALID"; }>
Defined in: packages/engine/planTemplate.mjs:36
TEMPLATE_VERSION#
constTEMPLATE_VERSION:1=1
Defined in: packages/engine/planTemplate.mjs:33
Functions#
checkParamValue()#
checkParamValue(
spec,value): {code:"PARAM_TYPE";message:string; } | {code:"PARAM_INVALID";message:string; } | {code:"PARAM_ENUM";message:string; }
Defined in: packages/engine/planTemplate.mjs:75
Validate one parameter value against its declaration. Returns an error
{ code, message } or null. Pure.
Parameters#
spec
any
value
any
Returns#
{ code: "PARAM_TYPE"; message: string; } | { code: "PARAM_INVALID"; message: string; } | { code: "PARAM_ENUM"; message: string; }
createTemplateRegistry()#
createTemplateRegistry(
templates?):object
Defined in: packages/engine/planTemplate.mjs:240
A registry over template objects (the caller decides where they come from — this module owns no curated set). Every template is load-validated.
Parameters#
templates?
any[] = []
Returns#
object
get
get: (
name) =>any
Parameters
name
any
Returns
any
instantiate
instantiate: (
name,params) =>object
Parameters
name
any
params
any
Returns
object
steps
steps:
any[]
ticket
ticket:
any
version
version:
number=PLAN_VERSION
list
list: () =>
object[]
Returns
object[]
instantiate()#
instantiate(
template,params?):object
Defined in: packages/engine/planTemplate.mjs:152
Instantiate a LOADED template into a concrete plan.v1. Deterministic: the same template and params give a byte-identical plan. Throws TemplateError on a bad parameter; the result is validatePlan()-checked.
Parameters#
template
any
params?
Returns#
object
steps
steps:
any[]
ticket
ticket:
any
version
version:
number=PLAN_VERSION
loadTemplate()#
loadTemplate(
raw):object
Defined in: packages/engine/planTemplate.mjs:169
Validate and normalise a template object. Refuses (TemplateError) at LOAD
time: an unknown flow, an undefined parameter, a placeholder where it is
forbidden, a malformed parameter, or an example that does not itself
yield a valid plan.
Parameters#
raw
any
Returns#
object
description
description:
any=raw.description
name
name:
any=raw.name
parameters
parameters:
object=params
steps
steps:
any=raw.steps
summary?
optionalsummary?:any=raw.summary
templateVersion
templateVersion:
number=TEMPLATE_VERSION
ticket
ticket:
any=raw.ticket
loadTemplateDir()#
loadTemplateDir(
dir):any
Defined in: packages/engine/planTemplate.mjs:267
Load every *.json in a directory the CALLER names (sorted, so the result
is deterministic). A missing directory is an error, not an empty set.
Parameters#
dir
string
Directory of *.json plan templates.
Returns#
any
The parsed templates, in file-name order.
Throws#
TEMPLATE_NOT_FOUND when the directory cannot be read.
resolveParams()#
resolveParams(
template,params?):object
Defined in: packages/engine/planTemplate.mjs:103
Validate supplied parameters against a loaded template and return the resolved values (defaults applied). Throws TemplateError listing every problem, by name.
Parameters#
template
any
params?
Returns#
object