Files
JetCore/docs/JetCore.tex
T
brad ArantandClaude Opus 5.5 2847ce5fa7 Add jetc --lint-sql to find <sql> that pastes values (phase 2)
Implements phase 2 of docs/design-sql-bound-parameters.md. jetc --lint-sql
[--strict] <file|dir>... lists each <sql> whose statement contains a $[...]
or #[...] reference instead of a <bind>, with file:line and where each value
comes from. Row values ($[.col], $[session.col], $[?N], $[#]) are only
reported with --strict. References in <bind>, <if>, <set> and the other
attribute-only tags, <comment> and |> <| are skipped. A custom tag defined
as <sql><container></sql> (barant.com's <showtable>) is checked at each use.
Exit status is 0 for none found, 1 for findings, 2 for an unreadable path.

- jetc/JetLint.*: the scanner; jetc.cpp: the option
- build scripts and runbindtests.sh: link JetLint.cpp
- tests/runlinttests.sh and tests/lintsql/: fixtures and expected output
- docs: worklist for the local copies of both sites, design doc status,
  manual note on the lint

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 20:29:28 -08:00

734 lines
19 KiB
TeX

\documentclass{book}
\usepackage{fontspec}
\setmainfont{Roboto}
\title{JET Extension Tags}
\author{Bradford Matthew Arant Sr.}
\date{\today}
\begin{document}
\maketitle
\tableofcontents
\chapter{Introduction}
JET will pass through the untagged areas to the output without any
modifications. Data contained within the tags may modify their
containers before placing any output. The space taken by the tag
itself is not passed to the output and will not appear in the output.
Skip Blank Lines options on containers will skip passing any blank
lines or line containing only whitespace to the output.
\section{Use Cases}
\subsection{World Wide Web Site}
\subsection{API Handling}
\subsection{Asterisk Dial Plan Generator Tool}
\chapter{Tags and Attributes}
XML style tagging is used to insert functions and other behaviors into
the script. As the document contents are output a tag may be inserted
to perform the desired function and affect the output.
Tag attributes are used to pass parameters into the operations and
functionality for each tag.
Outputting a database from mysql may be performed using the <mysql\> tag
in combination with the <ifrow\>, <whilerow\> and <sql\> tags.
\chapter{User Defined Tags and Tag Libraries}
You can define your own tag definitions and use them within your JET
scripts.
Keywords are not defined as part of the tag definition and any
attribute added to the implementation of the tag is passed into the
tag process as a local variable for that container.
Tag definitions can also be defined as scoped or unscoped, as follows:
scoped - local variables using the \#[n] format can be scoped to just
your tag contents. Access to local variables where your tag is being
used must use the 'parent' scope option to retrieve variables from the
parent.
unscoped - local variables are shared with the parent tag environment
and are not unique to your tag definition.
A <container /> tag can be inserted into the container and will take
the contents of the container at runtime and insert it into the output
when processing the user defined tag definition. The container tag of
the the <container /> is processed before the container containing the
<container /> so that local variabls can be set and processed that
will affect the tags overall output.
Tags are many times nested with tags running within the container of a
higher tag.
\chapter{Variables and Variable Types}
Variables are used to contain dynamic content values and can be
sourced from several locations and limited in scope depending on use.
Some variable types can be set to reflect script state or are read
only from other outside sources of data.
Jet tags can be either scoped or unscoped.
The following is a list of
variable types and a brief description of their source:
\begin{itemize}
\item Global - values can be initialized using the set tag and
specifying the scope of global.
\item Local -
\item Keyword - within a tag's container we may access the keyword
values specified on the containing tag.
\item Session - values stored in the session file with the set tag and
a scope of session. They persist across requests from the same browser.
\item Environment -
\item CGI Variables -
\end{itemize}
\section{Global Variables}
Global variables are available to all logic once the values have been
set.
Global variables are accessed throughout the procedure with the
\$[name] syntax.
Global is the default if the scope is
not specified for any function that writes to a variable.
\section{Local Variables}
Local variables are established using the set tag and specifying a
scope of local. Local variables are typically only available within
the container where they are defined. Some containers may not be
capable of storing local variables (i.e. set tag) and are inheriting
the local scope from their parent tag.
\section{Session Variables}
Session variables are stored in the session file for the current
session and remain available to later requests from the same browser.
Session control must be enabled (see Session Control).
A session variable is written with the set tag and a scope of
session:
\begin{verbatim}
<set name="_login_id" value="$[login_id]" scope="session">
\end{verbatim}
The name can be any variable name. It does not need an @ prefix.
Session variables are read with the \$[@name] syntax, for example
\$[@\_login\_id].
Setting a session variable does not also set a global variable of
the same name. When the same request needs to read the value as
\$[name], set it with both scopes:
\begin{verbatim}
<set name="_login_id" value="$[login_id]">
<set name="_login_id" value="$[login_id]" scope="session">
\end{verbatim}
\section{Keyword Variables}
Keyword variables are set when they are specified on a containing tag.
Within the container you can access the variable using the syntax
\$[\%name].
The variable retrieved is not processed for variable resolution.
\section{Environment Variables}
Environment variables are values existing in the exported list of value/pairs as provided by the operating system process. Apache, NGINX as well as other HTML server platforms provide environment variables to describe the requests being handed in.
\section{CGI Variables}
When operating Jet in CGI mode you have access to the form data
submitted by the remote client (usually a browser or curl request)
using the POST method.
\sectionmark{Expressions}
Expressions are used to perform complicated calculations (arithmetic), perform
comparisons between values (boolean), manipulate strings (string) or
perform operations on dates (date).
\chapter{Expressions}
\section{Operators}
Operators are used to perform arithmetic or boolean operations on
arguments to derive a particular result. There are two types of
operators, as follows:
\begin{itemize}
\item Arithmetic -
\item Boolean -
\end{itemize}
\subsection{Arithmetic Operators}
\subsection{Boolean Operators}
\section{Function Reference}
\section{Date Functions}
\subsection{datediff}
\subsection{unixtime}
\section{Math Functions}
\subsection{abs}
Returns the absolute value of the given parameter.
\subsection{acos}
Returns to arc cosine of the given parameter.
\subsection{asin}
\subsection{atan}
\subsection{cos}
\subsection{floor}
\subsection{ceil}
\subsection{max}
Returns the greatest value item from a list of comma seperated values in a
list.
\subsection{min}
Returns the least value item from a list of comma seperated values in
a list.
\subsection{pow}
\subsection{random}
Use the random function to return a random number between 0 and 1.
\subsection{sin}
\section{String Functions}
String functions are provided to accelerate the building and parsing of
strings passed into the expression. Numbers can be treated as a string or
a number depending on the function called and the data state of the values
being manipulated.
\subsection{concat}
The concat function is used to assemble a string by concatenating one or
more values to formulate the resulting string.
\subsection{integer}
\subsection{left}
Use the left function to return the number of characters specified in
the second parameter from the parameter passed as the first parameter.
If the number of characters to return is greater than the length of
the first parameter then the entire parameter is returned.
\subsection{ltrim}
Use the ltrim function to remove the leading blanks (spaces, tabs and
newlines) from a value. Trailing blanks are kept.
\begin{verbatim}
ltrim(' abc ') returns 'abc '
\end{verbatim}
\subsection{reverse}
\subsection{right}
\subsection{round}
Use the round function to round a numeric value to the specified
number of digits after the decimal point.
\subsection{rtrim}
Use the rtrim function to remove the trailing blanks (spaces, tabs and
newlines) from a value. Leading blanks are kept.
\begin{verbatim}
rtrim(' abc ') returns ' abc'
\end{verbatim}
\subsection{substring}
Use the substring operation to extract a portion of a string and return
the value as a string.
\subsection{tolower}
\subsection{toupper}
\subsection{trim}
Use the trim function to remove the blanks (spaces, tabs and newlines)
from both ends of a value. See also ltrim and rtrim.
\begin{verbatim}
trim(' abc ') returns 'abc'
\end{verbatim}
\subsection{expr}
Use the expr function to parse the string contents contained in the expr string.
\chapter{Common Gateway Interface Features}
JET extension tags provides options for enabling the processing of
data using the Common Gateway Interface (CGI) specification used by
Apache and NGINX as well as other HTTP server applications. This makes
JET a powerful tool for creating web interfaces and API handler
environments for various javascript frameworks as well as just native
HTML style interaction.
To enable the CGI features within a requested document you can specify
the cgi="true" attribute on a <jet> tag containing the document or
<jet /> tag contained within the document.
When you enable the CGI interface the script will look for specific
environment variables used to retrieve the input data from the browser
interface and automatically provide these values to the JET scripting
using the variables interface. There are currently three supported
data formats or content types through this interface. These content
types are:
formdata/urlencoded
mutipart/formdata
text/json
\section{Session Control}
Common use of the CGI is requiring the transaction based interaction
of a web browser to maintain a state between interactions. JET 2.0
provides a built in mechanism to assist in managing a session concept.
This approach uses a single session cookie to identify the session to
the back end services.
By specifying a seesiondir keyword on the <jet> tag you enable the
session control functionality. Upon the delivery of a request that
does not contain a session 'token' a session token will be generated
for the request and a cookie will be returned in the reponse
containing the session token. Additionally, a session file is placed
into the directory named after the token. Captured session data will
become available to future requests coming into the server and made
available through the variable formats for the session.
Under APIServer, session control is enabled for a site by its
sessionDir setting in the server configuration instead of the <jet>
tag.
Use the <set> tag with scope="session" to store a value in the
session, and \$[@name] to read it back (see Session Variables).
The session tags in SESSIONCTL.tag are deprecated for session
management. Its setenv tag has been removed, and the startsession and
endsession tags are no longer provided. Use scope="session" instead.
\chapter{Tag Reference}
This chapter will cover all the tags and parameters required to
perform the operations that JET provides.
A special character sequence is used to exclude a section from tag and
variable parsing. This sequence is |> this is not parsed or resolved
<|. This takes affect through all levels and depths of tag processing
and is different from the <exclude /> tag as exclude may be further
parsed if output is again evaluated.
\section{bind}
Use the bind tag inside an sql tag to supply the value for a ?
placeholder in the statement. Each bind fills the next ? in order. The
value is escaped or checked before it reaches the server, so whatever
it contains can never change the meaning of the statement. Use bind for
every value that comes from a request, a cookie or a session instead of
writing \$[name] into the statement text.
The bind tag has no closing tag and produces no output. It must be
inside an sql tag, although it may be inside other tags (if, for and so
on) within that sql tag.
\begin{verbatim}
<sql>select id, name from users where email=? and status=?
<bind value="$[email]">
<bind value="ACTIVE">
</sql>
\end{verbatim}
The attributes are:
value - the value to bind. Required. Any expression or variable
reference may be used here.
type - how the value is checked and sent. The values are:
\begin{itemize}
\item string - the default. Quoted and escaped.
\item int - a whole number of up to 19 digits, optionally negative.
Sent without quotes.
\item decimal - a number with an optional fraction, for example
-12.50. Sent without quotes.
\item bool - 1, true, yes, 0, false or no (any case). Sent as 1 or 0.
\item date - YYYY-MM-DD.
\item datetime - YYYY-MM-DD HH:MM or YYYY-MM-DD HH:MM:SS.
\item ident - a column or table name, or a sort direction, for the
places SQL cannot take a value (ORDER BY and so on). Requires the allow
attribute. Names are sent in backticks; ASC and DESC are sent as they
are.
\end{itemize}
null - set to empty to send SQL NULL when the value is empty. Without
it an empty value is sent as an empty string (and is an error for int,
decimal, bool, date and datetime).
allow - for type="ident" only. A comma separated list of the values
that are permitted. Any other value is an error.
\begin{verbatim}
<sql>select * from products order by ? ?
<bind value="$[sort]" type="ident" allow="name,price,created">
<bind value="$[dir]" type="ident" allow="ASC,DESC">
</sql>
\end{verbatim}
A ? inside a quoted string, a backtick name or a comment in the
statement is not a placeholder. An sql tag that contains no bind tags
is run exactly as written, so a ? in it is left alone.
These are errors, and can be caught with try/catch: a value that does
not fit its type, an ident that is not in the allow list, a bind
outside an sql tag, a bind with no value, an unknown type, and a
statement whose number of ? placeholders differs from its number of
bind tags. The error text never contains the bound value itself.
To find the sql tags that still write values into the statement text,
run the jet compiler's lint over a site:
\begin{verbatim}
jetc --lint-sql /path/to/site
\end{verbatim}
It prints the file and line of each one, with the variables it uses.
Add \texttt{-{}-strict} to include values from the rows of an earlier query.
\section{call}
Use the call tag to evoke an executable file from a jet script.
The atrributes are:
pgm
argn
name
input
error
The call tag is unscoped.
\begin{verbatim}
<call pgm="ls" arg1="-al" name="listing" />
\end{verbatim}
will call the ls command with parameter -al and place the output into
a variable named 'listing'.
\section{comment}
Use the comment tag to create a section in the jet script that can be
used for making comments and is ignored by the jet reader.
The comments tag has no attributes.
\section{cookie}
Use the cookie tag to specify a cookie when using the CGI features
of JET.
\section{dump}
Use the dump tag to display the contents of all the global, local and
cgi cariables to a specified file.
The attributes are:
file
\section{exclude}
Use the exclude tag to exclude a conainer contents from normal parsing
and variable resolution.
\section{expr}
\section{for}
Use the for tag to iterate a tag container for a logical number of
times.
The attributes are:
start
end
step
name - defines a name for the iterator that will be available within
the loop.
scope - defines the scope of the iterator for the loop.
\section{header}
Use the header tag to output a header prior to outputting the process
buffer to the requester.
The attributes are:
name
expr
value
container
\section{if/else}
Use the if tag to perform a conditional output on the tag container.
An optional else container provides alternate output in the event the
condition is not met.
The attributes are:
value1
value2
type
expr
\section{ifrow/else}
Use the ifrow tag to output the tag container if a row exists in the
mysql tag. An optional else container provides alternate output in the
event that there is no row for the sql result.
The attributes are:
sessionid
\section{include}
Use the include tag to include another content file at the location of
the include tag.
The attributes are:
file
\section{jet}
Use the jet tag to specify parameters for the jet parsing session and
to control the output options.
\section{mysql}
Use the mysql tag to specify parameters for connecting to a mysql
server. The container of the tag is where you can specify the sql
statement and method of processing the result output of the executed
sql statement. The mysql session created is valid only withon the
container of this tag.
The attributes are:
host
database
user
password
sessionid
\section{read}
Use the read tag to read the contents of a file contained on the local
file system into a variable for further output or processing.
The attributes are:
file
name
\section{set}
Use the set tag to store initialize a variable to a value contained in
a value attribute, the result of an expression (expr) attribute or the
contents of the set tag container.
The attributes are:
name
expr
value
container
scope - where the variable is stored. The values are:
\begin{itemize}
\item global - the default. Available to all logic for the rest of the
request.
\item local - available only within the container where it is set.
\item parent - stored in the scope of the enclosing tag.
\item session - stored in the session file and kept across requests.
Requires session control. See Session Variables.
\end{itemize}
\section{sql}
Use the sql tag to specify an sql statement to run on the sql server
specified in the mysql tag.
As long as sql statements are executed within the same mysql
containing tag then the same mysql session is used for each sql
statement.
Values that come from a request, a cookie or a session should be
passed with bind tags and ? placeholders rather than written into the
statement text. See the bind tag.
\begin{verbatim}
<sql>delete from cart_item where session_uuid=? and sku=?
<bind value="$[_session_id]">
<bind value="$[sku]">
</sql>
\end{verbatim}
A statement that changes the connection character set (SET NAMES, SET
CHARACTER SET and similar) is refused. The connection always uses
utf8mb4.
The attributes are:
sessionid
container
\section{stream}
Use stream tag to output data from the server without waiting for the
standard output buffering and processing of the JET script. This is
useful for outputting images and streams for audio and video without
the server having to load the whole thing into RAM first.
The attributes are:
file
\section{system}
Use the system tag to execute a bash shell command within the JET
script.
\section{tag}
Use the tag tag to define a new tag definition for use within the
script.
Tags are normally defined globally and can be used anywhere within the
script.
Tags can also be defined within other tags and the scope of those tags
is only within the defining tag's container. The enclosed tag
definition will not be available globally.
\section{until}
Use the until tag to process a container at least once and
continue to process the container until the specified condition is met.
Note that this tag always processes the container at least once.
Be careful not to create a never ending loop by not modifying any of
the condition parameters specified in the condition clause.
\section{while}
Use the while tag to process a container if the specified condition is
true.
Note that the container may not be processed if the condition is never
met.
Be careful not to create a never ending loop by not modifying any of
the condition parameters specified in the condition clause.
\section{whiledir}
Use the whiledir tag to loop a directory path to the container for
processing.
\section{whilerow}
Use the whilerow tag in combination with mysql and sql tags to provide
a container to process for each row retrieved by the sql statement.
\section{write}
Use the write tag to write data to the local file system.
\end{document}