Private
changefor every json pointer, we have multiple callbacks that are stored in a Set
Contextual data for the template processing.
Debugger utility for the template processor.
Contains any errors encountered during template processing.
Private
executionExecution plans 'from' a given JSON Pointer. So key is JSON Pointer and value is array of JSON pointers (a plan)
Private
Readonly
executionA queue of execution plans awaiting processing.
function generators can be provided by a caller when functions need to be created in such a way that they are somehow 'responsive' or dependent on their location inside the template. Both the generator function, and the function it generates are asynchronous functions (ie they return a promise). $import is an example of this kind of behavior. When $import('http://mytemplate.com/foo.json') is called, the import function is actually genrated on the fly, using knowledge of the json path that it was called at, to replace the content of the template at that path with the downloaded content.
Represents the raw input for the template processor.
Private
isFlag indicating if the template processor is currently initializing.
Represents the logger used within the template processor.
Maps JSON pointers of import paths to their associated meta information.
Readonly
onAllows caller to set a callback to propagate initialization into their framework
Configuration options for the template processor.
Contains the processed output after template processing.
Allows a caller to receive a callback after the template is evaluated, but before any temporary variables are removed. This function is slated to be replaced with a map of functions like onInitialize
Allows a caller to receive a callback after the template is evaluated, but before any temporary variables are removed. This function is slated to be replaced with a map of functions like onInitialize
A set of tags associated with the template.
Private
tempThis object mirrors the template output in structure but where the output contains actual data, this object contains MetaInfo nodes that track metadata on the actual nodes
Private
timerPrivate
Readonly
uniqueA unique identifier for the template processor instance.
List of warnings generated during template processing.
Static
DEFAULT_Default set of functions provided for the template processor.
Cancels a Timeout
object created by setInterval()
.
v0.0.1
Debounces a function, ensuring that it is only called once after a specified time has elapsed since the last call.
The function to debounce.
The number of milliseconds to wait before invoking the function.
A debounced function with the same type as the original function.
// Example usage:
function myFunction(value: string) {
console.log('Value:', value);
}
const debouncedFunction = debounce(myFunction, 500);
debouncedFunction('First call');
debouncedFunction('Second call');
debouncedFunction('Third call');
Performs a fetch request and enhances error handling.
If the response is not ok, it rejects with a custom error object that includes a .json()
method.
This .json()
method, when called, returns the error object itself, facilitating error handling
for scenarios where the caller expects to call .json()
on the response.
The URL to fetch.
Optional
opts: objectOptional fetch options.
A promise that resolves to the fetch response. If the response is not ok, it rejects with a custom error object consistent with Stated template-level error handling e.g. {error:{message:"..."}}.
The custom error object with a .json()
method if the response is not ok. The error
object structure is: { error: { message: string } }.
These functions are commonly used utilities available for usage within the template processor's context. You can replace set this to determine which functions are available from templates
Static
Private
NOOPStatic
Private
_isPrivate
_evaluatePrivate
_evaluatePrivate
_setPrivate
_strictPrivate
adjustPrivate
Sometimes we need to import a simple expression string that is not nested in an object. for example if we {"msg":"$import('${'hello ' & to }')"), then we are importing an expression directly into the parent, not nesting in an object. In this case we must slice off the last element of the rootJsonPointer, because to not slice it off would imply that the target of the expression is inside the msg field, but the intention when we import a simple expression is target the parent object which holds the msg field.
either the original rootJsonPointer, or one that has been trimmed to point to the parent of rootJsonPtr
Private
allPrivate
applyPrivate
cachePrivate
callPrivate
createPrivate
drainPrivate
evaluatePrivate
evaluatePrivate
evaluatePrivate
executePrivate
executePrivate
executePrivate
extractPrivate
fetchPrivate
generatePrivate
generatePrivate
generatePrivate
When $forked is called, it must push the current output onto the forkStack so it can be restored on $joined, and it must replace the output with a copy of the output.
Private
generatePrivate
The $joined(/foo, data) function pops the forkstack and can return us to ordinary non-forked operation if the pop operation empties the fork stack
Private
generatePrivate
The $set(/foo, data) command may be operating inside the context of a $forked. If this is the case then $setData is intercepted here and we use the setDataForked function which applies changes to forked output
Private
getPrivate
getTemplate processor initialize can be called from 2 major use cases
the object representing the importedSubtemplate
defaults to "/" which is to say, this importedSubtemplate is the root importedSubtemplate. When we $import a importedSubtemplate inside an existing importedSubtemplate, then we must provide a path other than root to import into. Typically, we would use the json pointer of the expression where the $import function is used.
if provided, output is set to this initial value
Initializes the current TemplateProcessor instance using the output data from a given snapshot object. This method is designed for use with an already constructed TemplateProcessor instance, allowing it to be initialized (or re-initialized) with specific output data from a snapshot. This can be particularly useful for setting or resetting the processor's state based on dynamic conditions or to rehydrate the processor from a previously saved state without constructing a new instance.
A snapshot object containing only the output data for initializing the TemplateProcessor.
A promise that resolves once the TemplateProcessor has been initialized with the output data from the snapshot.
const snapshot = {"output":{...}, "options":{...}, "template":{...}};
const tp = TemplateProcessor.constructFromSnapshotObject(snapshot);
await tp.initializeFromSnapshotObject(snapshot)
.then(() => console.log('TemplateProcessor initialized from snapshot output.'));
Private
isPrivate
isPrivate
temp vars are in scope if all tags are present OR the expression's fieldname ends in !, which makes it an absolutely temporary variable since.
Private
localPrivate
logPrivate
makePrivate
mutatePrivate
parseURLPrivate
populatePrivate
propagateOptional
cbFn: DataChangeCallbackPrivate
removePrivate
removePrivate
resetPrivate
setSets or deletes data based on the specified operation.
The JSON pointer indicating where to apply the operation.
Optional
data: any = nullThe data to be used with the set or setDeferred operation.
Optional
op: Op = "set"The operation to perform - setDeferred is for internal use
A promise with the list of json pointers touched by the plan
Sets a data change callback function that will be called whenever the value at the json pointer has changed
of form (data, ptr:JsonPointerString, removed?:boolean)=>void
Calling setDataForked allows the mutation and its reaction (fromPlan) to begin executing immediately without queuing/seriealizing/blocking on other plans. This is possible because a forked planStep contains a write-safe copy of this.output (essentially a 'snapshot' in MVCC terminology) and therefore the mutation and propagation of the fromPlan are isolated, just like snapshot isolation levels on Postres or other MVCC databases. So, do not await this method. Just let 'er rip.
Private
setPrivate
setPrivate
setupCreates a stringified snapshot of the current state of the TemplateProcessor instance, including its input, output, and options.
A JSON string representing the snapshot of the TemplateProcessor's current state, including template input, processed output, and options.
const tp = new TemplateProcessor(template, context, options);
const snapshotString = await tp.snapshot();
// snapshotString contains a JSON string with the template, output, and options of the TemplateProcessor
Private
sortPrivate
topologicalPrivate
validatePrivate
withPrivate
wrapStatic
Private
compileStatic
constructConstructs a new TemplateProcessor instance from a given snapshot object, but does NOT initialize it. This method allows the caller the opportunity to register dataChangeCallbacks and so forth before template evaluation begins, providing more control over the initialization process.
A snapshot object containing template, options, and output data for initializing the TemplateProcessor.
Optional
context: {} = {}An optional context object to be used by the TemplateProcessor.
A new TemplateProcessor instance constructed from the snapshot data, not yet initialized.
const snapshot = {"template":"...", "options":{}, "output":"..."};
const tp = TemplateProcessor.constructFromSnapshot(snapshot);
// Register callbacks or perform other setup operations here
await tp.initialize();
Static
Private
deepStatic
Private
dependsStatic
fromConstructs and initializes a new TemplateProcessor instance from a given snapshot string. This method parses the snapshot string, constructs a new TemplateProcessor with the parsed data, and then initializes it. It is a convenient method for quickly rehydrating and preparing a TemplateProcessor instance from a saved state.
A JSON string snapshot from which to initialize the TemplateProcessor.
Optional
context: {} = {}An optional context object to be used by the TemplateProcessor.
A promise that resolves with the newly initialized TemplateProcessor instance.
const snapshotString = '{"template":"...","options":{},"output":"..."}';
TemplateProcessor.initializeFromSnapshot(snapshotString, context)
.then(tp => console.log('TemplateProcessor initialized from snapshot.'));
Static
fromStatic
loadLoads a template and initializes a new template processor instance.
The template data to be processed.
Optional
context: {} = {}Optional context data for the template.
Returns an initialized instance of TemplateProcessor
.
Static
Private
preparePrivate
this method mutates the Snapshot's template in place to merge accumulated output data into it. It does this by
Net effect is that pure data that had been shoved into the output, at runtime gets transfered into the template. Now it is safe to initialize from this Snapshot and we will not have a situation where there is pure data in the output with no corresponding MetaInfo to mark it as materialized__
Static
Private
simpleGenerated using TypeDoc
This is the main TemplateProcessor class.
Remarks
The TemplateProcessor class is responsible for processing templates and interfacing with your program that may provide changing inputs over time and react to changes with callbacks. Many examples can be found in
src/test/TemplateProcessor.test.js
Example: Initialize a simple template stored in local object 'o'
Example: Pass the TemplateProcessor a context containing a function named `nozzle` and a variable named `ZOINK`
Example: Parse template from JSON or YAML
Example: React to changes using data change callbacks on various locations in the template