{"modulePath":"github.com/dracory/nodebase","version":"v0.7.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package trigger\n\nPackage trigger contains the trigger node implementation.\n\n## Types\n\n```go\ntype TopicScope bool\n```\nTopicScope decodes Node-RED's bytopic representations into a bool: exported flows carry the enum strings \"topic\" (per-topic timers) and \"all\" (one shared timer), while the editor schema writes booleans. true means per-topic.\n\n```go\nfunc (s *TopicScope) UnmarshalJSON(raw []byte) error\n```\nUnmarshalJSON accepts the enum strings, booleans and boolean strings.\n\n```go\ntype TriggerConfig struct {\n\t// Op1 / Op1Type configure the value emitted immediately on output_1.\n\t// Types: str (default) | num | bool | json | payload (pass input\n\t// through) | date (current timestamp ms) | bin (JSON byte array or\n\t// base64) | env (environment variable).\n\tOp1     string `json:\"op1\"`\n\tOp1Type string `json:\"op1type\"`\n\t// Op2 / Op2Type configure the value emitted when the timer expires.\n\tOp2     string `json:\"op2\"`\n\tOp2Type string `json:\"op2type\"`\n\t// Then selects the follow-up mode: \"wait\" (default, send op2 after\n\t// the delay), \"loop\" (resend op1 every interval until reset) or\n\t// \"block\" (wait to be reset — further messages are dropped until a\n\t// reset or the delay expires). Node-RED serializes the mode through\n\t// the Duration sign instead: negative = loop, zero = block; an\n\t// empty Then falls back to that convention.\n\tThen string `json:\"then\"`\n\t// Duration is the delay before op2 fires (in Units). Node-RED\n\t// encodes the then-mode in its sign: negative = resend every\n\t// |Duration|, zero = wait to be reset.\n\tDuration float64 `json:\"duration\"`\n\t// Units is the duration unit: ms (default) | s | min | hr.\n\tUnits string `json:\"units\"`\n\t// Extend restarts the pending timer on each new message.\n\tExtend bool `json:\"extend\"`\n\t// OverrideDelay lets Metadata[\"delay\"] replace the configured\n\t// duration (same units).\n\tOverrideDelay bool `json:\"overrideDelay\"`\n\t// Outputs selects where op2 goes: 1 = output_1, 2 = output_2.\n\tOutputs int `json:\"outputs\"`\n\t// ByTopic keeps a separate timer per Metadata[\"topic\"].\n\tByTopic TopicScope `json:\"bytopic\"`\n\t// Reset is Node-RED's reset field: a message whose payload\n\t// stringifies to this value resets pending timers (in addition to\n\t// msg.reset).\n\tReset string `json:\"reset\"`\n\t// ResetValue is an accepted alias for Reset.\n\tResetValue string `json:\"resetValue\"`\n}\n```\nTriggerConfig holds configuration for the trigger node — the Node-RED trigger equivalent (simplified field names).\n\n```go\ntype TriggerNode struct {\n\t*nodebase.BaseNode\n\t// contains filtered or unexported fields\n}\n```\nTriggerNode sends one message immediately, then optionally a second after a configurable delay — the Node-RED trigger node. The immediate output always routes to output\\_1 (via SelectPorts); the delayed output is emitted asynchronously on output\\_2 (outputs=2) or output\\_1. Metadata\\[\"reset\"] clears pending timers and drops the message.\n\n```go\nfunc NewTriggerNode(node nodestore.NodeInterface, config *TriggerConfig, host nodebase.NodeHost) *TriggerNode\n```\nNewTriggerNode creates a new trigger node\n\n```go\nfunc (n *TriggerNode) Execute(ctx context.Context, input nodestore.MessageInterface) (nodestore.MessageInterface, error)\n```\nExecute emits op1 immediately (returned as the output, routed to output\\_1 by SelectPorts) and arms/rearms the follow-up per the then-mode: wait (op2 after the delay), loop (resend op1 every interval until reset) or block (drop further messages until a reset or the delay expires). A truthy Metadata\\[\"reset\"] — or a payload equal to the configured reset value — clears the topic and drops the message.\n\n```go\nfunc (n *TriggerNode) SelectPorts(input, output nodestore.MessageInterface) []string\n```\nSelectPorts routes the immediate output (op1) to output\\_1 only.\n\n```go\nfunc (n *TriggerNode) Validate() error\n```\nValidate checks the trigger node configuration\n\n","path":"github.com/dracory/nodebase/trigger","name":"trigger","synopsis":"Package trigger contains the trigger node implementation.","isRedistributable":true}
