- ProjectFile
- TeraFy
- settings
- events
- dom
- methods
- plugins
- send
- sendRaw
- rpc
- acceptMessage
- acceptPostboxes
- createProjectStatePatch
- applyProjectStatePatchLocal
- init
- detectMode
- injectComms
- injectStylesheet
- injectMethods
- debug
- set
- setIfDev
- use
- mixin
- toggleDevMode
- toggleFocus
- selectProjectFile
- getProjectFiles
- getProjectFile
- createProjectFile
- handshake
- setServerVerbosity
- User
- getUser
- requireUser
- Project
- getProject
- getProjects
- setActiveProject
- requireProject
- selectProject
- getProjectState
- setProjectState
- setProjectStateDefaults
- setProjectStateFlush
- setProjectStateRefresh
- saveProjectState
- replaceProjectState
- applyProjectStatePatch
- subscribeProjectState
- FileFilters
- selectProjectFile
- deleteProjectFile
- setProjectFile
- selectProjectLibrary
- getProjectLibrary
- setProjectLibrary
- projectLog
- setPageUrl
- setPageTitle
- uiAlert
- uiProgress
- uiWindow
- uiSplat
A project file fetched from TERA
A UUID string representing the unique ID of the file
Type: String
Relative name path (can contain prefix directories) for the human readable file name
Type: String
CSS class to use as the file icon
Type: String
Full path to the file This is also used as the unique identifier within the project
Type: String
Fully qualified URL to view / access / download the file from TERA This will usually open an edit UI within the TERA site
Type: String
Rewrite of the URL where the absolute URL has been removed in place of a relative path, assuming the owner project is active This is used to direct to the edit/view/download UI when the files project is active and is usually used in place of URL for TERA related operations
Type: String
An object representing meta file parts of a file name
Type: Object
basename
String The filename + extention (i.e. everything without directory name)filename
String The file portion of the name (basename without the extension)ext
String The extension portion of the name (always lower case)dirName
String The directory path portion of the name
A date representing when the file was created
Type: Date
A human readable, formatted version of "created"
Type: String
A date representing when the file was created
Type: Date
A human readable, formatted version of "modified"
Type: String
A date representing when the file was last accessed
Type: Date
A human readable, formatted version of "accessed"
Type: String
Size, in bytes, of the file
Type: Number
A human readable, formatted version of the file size
Type: String
The associated mime type for the file
Type: String
Additional meta information for the file
Type: Object
- See: getProjectFile()
Fetch the raw file contents as a Blob
returns {Blob} The eventual raw file contents as a Blob
- See: setProjectFile()
Overwrite the contents of a file with new content
Returns Promise A promise which resolves when the operation has completed
- See: getProjectLibrary()
Fetch the file contents as an array of Reflib refs
Returns Promise<Array<Ref>> An eventual array of RefLib references
- See: setProjectLibrary()
Overwrite the contents of a file with a new collection of Reflib refs
refs
Collection
Array<RefLibRef> of references for the selected library
Returns Promise A promise which resolves when the operation has completed
Compress a file state down into a serializable entity By default this computes a Structured Clone which can be stringified
Returns Object A Structured Clone compatible representation of this ProjectFile instance
Restore an entity created with serialize
data
Object An input object created viaProjectFiles.serialize()
Returns ProjectFile A ProjectFile instance setup against the deserializzed data
Main Tera-Fy Client (class singleton) to be used in a frontend browser
Various settings to configure behaviour
Type: Object
devMode
Boolean Operate in devMode - i.e. force outer refresh when encountering an existing TeraFy instanceverbosity
Number Verbosity level, the higher the more chatty TeraFY will be. Set to zero to disable alldebug()
call outputmode
("detect"
|"parent"
|"child"
|"popup"
) How to communicate with TERA. 'parent' assumes that the parent of the current document is TERA, 'child' spawns an iFrame and uses TERA there, 'detect' tries parent and switches tomodeFallback
if communication failsmodeFallback
String Method to use when all method detection failsmodeTimeout
Number How long entities have in 'detect' mode to identify themselvessiteUrl
String The TERA URL to connect torestrictOrigin
String URL to restrict communications toList
Array<String> of sandbox allowables for the embedded if in embed modehandshakeInterval
Number Interval in milliseconds when sanning for a handshake
Event emitter subscription endpoint
Type: Mitt
DOMElements for this TeraFy instance
Type: Object
el
DOMElement The main tera-fy div wrapperiframe
DOMElement The internal iFrame element (ifsettings.mode == 'child'
)popup
Window The popup window context (ifsettings.mode == 'popup'
)stylesheet
DOMElement The corresponding stylesheet
List of function stubs mapped from the server to here
This array is forms the reference of TeraFy.METHOD()
objects to provide locally which will be mapped via TeraFy.rpc(METHOD, ...args)
Loaded plugins via Use()
Type: Array<TeraFyPlugin>
Send a message + wait for a response object
message
Object Message object to send
Returns Promise<any> A promise which resolves when the operation has completed with the remote reply
Send raw message content to the server
This function does not return or wait for a reply - use send()
for that
message
Object Message object to send
Call an RPC function in the server instance
method
String The method name to callargs
...any
Returns Promise<any> The resolved output of the server function
Accept an incoming message
rawMessage
Raw
MessageEvent message event to process
Listening postboxes, these correspond to outgoing message IDs that expect a response
Create + transmit a new project state patch base on the current and previous states The transmitted patch follows the JSPatch standard This function accepts an entire projectState instance, computes the delta and transmits that to the server for merging
newState
Object The local projectState to acceptoldState
Object The previous projectState to examine against
Returns Promise A promise which will resolve when the operation has completed
Client function which accepts a patch from the server and applies it to local project state The patch should follow the JSPatch standard This function is expected to be sub-classed by a plugin
patch
Array A JSPatch patch to apply
Returns Promise A promise which will resolve when the operation has completed
Initalize the TERA client singleton This function can only be called once and will return the existing init() worker Promise if its called againt
options
Object? Additional options to merge intosettings
viaset
Returns Promise<TeraFy> An eventual promise which will resovle with this terafy instance
Populate settings.mode
Try to communicate with a parent frame, if none assume we need to fallback to child mode
Returns Promise<String> A promise which will resolve with the detected mode to use
Find an existing active TERA server OR initalize one
Returns Promise A promise which will resolve when the loading has completed and we have found a parent TERA instance or initiallized a child
Inject a local stylesheet to handle TERA server functionality
Returns Promise A promise which will resolve when the loading has completed and we have found a parent TERA instance or initiallized a child
Inject all server methods defined in methods
as local functions wrapped in the rpc
function
Debugging output function
This function will only act if settings.devMode
is truthy
msg
...anymethod
("INFO"
|"LOG"
|"WARN"
|"ERROR"
) Logging method to use (optional, default'LOG'
)verboseLevel
Number The verbosity level to trigger at. Ifsettings.verbosity
is lower than this, the message is ignored (optional, default1
)
Set or merge settings
This function also routes 'special' keys like devMode
to their internal handlers
-
key
(String | Object) Either a single setting key to set or an object to merge -
value
any The value to set ifkey
is a string -
options
Object? Additional options to mutate behaviouroptions.ignoreNullish
Boolean If falsy, this forces the setting of undefined or null values rather than ignoring them when specifying values by string (optional, defaulttrue
)
Returns TeraFy This chainable terafy instance
- See: set()
Set or merge settings - but only in dev mode and only if the value is not undefined
key
(String | Object) Either a single setting key to set or an object to mergevalue
any The value to set ifkey
is a stringoptions
Object? Additional options to mutate behaviour
Returns TeraFy This chainable terafy instance
Include a TeraFy client plugin
mod
options
Object? Additional options to mutate behaviour during construction (pass options to init() to intialize later options)The
Object module function to include. Invoked as(teraClient:TeraFy, options:Object)
Returns TeraFy This chainable terafy instance
Internal function used by use() to merge an external declared singleton against this object
target
Object Initalied class instance to extendsource
Object Initalized source object to extend from
Set or toggle devMode This function also accepts meta values:
'toggle' - Set dev mode to whatever the opposing value of the current mode
'proxy' - Optimize for using a loopback proxy
devModeEnabled
("toggle"
|"proxy"
| Boolean) Optional boolean to force dev mode or specify other behaviour (optional, default'toggle'
)
Returns TeraFy This chainable terafy instance
Fit the nested TERA server to a full-screen This is usually because the server component wants to perform some user activity like calling $prompt
isFocused
(String | Boolean) Whether to fullscreen the embedded component (optional, default'toggle'
)
Require a user login to TERA If there is no user OR they are not logged in a prompt is shown to go and do so This is an pre-requisite step for requireProject()
options
Returns Promise A promise which will resolve if the there is a user and they are logged in
Fetch the files associated with a given project
-
options
Object Options which mutate behaviouroptions.autoRequire
Boolean RunrequireProject()
automatically before continuing (optional, defaulttrue
)options.lazy
Boolean If true, use the fastest method to retrieve the file list such as the cache. If false, force a refresh each time (optional, defaulttrue
)options.meta
Boolean Pull meta information for each file entity (optional, defaulttrue
)
Returns Promise<Array<ProjectFile>> A collection of project files for the given project
Fetch a project file by its name
-
id
-
name
String The name + relative directory path component -
options
(Object | String)? Additional options to mutate behaviour, if a string is givenoptions.subkey
is assumed
Returns Promise<ProjectFile> The eventual fetched ProjectFile (or requested subkey)
Create a new file This creates an empty file which can then be written to
name
String The name + relative directory path component
Returns Promise<ProjectFile> The eventual ProjectFile created
Return basic server information as a form of validation
date
Date Server date
Returns Promise<Object> Basic promise result
RPC callback to set the server verbostiy level
verbosity
Number The desired server verbosity level
User / active session within TERA
id
String Unique identifier of the useremail
String The email address of the current username
String The provided full name of the userisSubscribed
Boolean Whether the active user has a TERA subscription
Fetch the current session user
Returns Promise<User> The current logged in user or null if none
Require a user login to TERA If there is no user OR they are not logged in a prompt is shown to go and do so This is an pre-requisite step for requireProject()
-
options
Object? Additional options to mutate behaviouroptions.forceRetry
Boolean Forcabily try to refresh the user state (optional, defaultfalse
)
Returns Promise<User> The current logged in user or null if none
Project entry within TERA
Get the currently active project, if any
Returns Promise<(Project | null)> The currently active project, if any
Get a list of projects the current session user has access to
Returns Promise<Array<Project>> Collection of projects the user has access to
Set the currently active project within TERA
Ask the user to select a project from those available - if one isn't already active Note that this function will percist in asking the uesr even if they try to cancel
-
options
Object? Additional options to mutate behaviouroptions.autoSetActiveProject
Boolean After selecting a project set that project as active in TERA (optional, defaulttrue
)options.title
String The title of the dialog to display (optional, default"Select a project to work with"
)options.noSelectTitle
String Dialog title when warning the user they need to select something (optional, default'Select project'
)options.noSelectBody
String Dialog body when warning the user they need to select something (optional, default'A project needs to be selected to continue'
)
Returns Promise<Project> The active project
Prompt the user to select a project from those available
-
options
Object? Additional options to mutate behaviouroptions.title
String The title of the dialog to display (optional, default"Select a project to work with"
)options.allowCancel
Boolean Advertise cancelling the operation, the dialog can still be cancelled by closing it (optional, defaulttrue
)options.setActive
Boolean Also set the project as active when selected (optional, defaultfalse
)
Returns Promise<Project> The active project
Return the current, full snapshot state of the active project
-
options
Object? Additional options to mutate behaviouroptions.autoRequire
Boolean RunrequireProject()
automatically before continuing (optional, defaulttrue
)
Returns Promise<Object> The current project state snapshot
Set a nested value within the project state Paths can be any valid Lodash.set() value such as:
- Dotted notation - e.g. `foo.bar.1.baz`
- Array path segments e.g. `['foo', 'bar', 1, 'baz']`
-
path
(String | Array<String>) The sub-path within the project state to set -
value
any The value to set -
options
Object? Additional options to mutate behaviouroptions.save
Boolean Save the changes to the server immediately, disable to queue up multiple writes (optional, defaulttrue
)
Returns Promise A promise which resolves when the operation has been dispatched to the server
- See: setProjectState()
Set a nested value within the project state - just like setProjectState()
- but only if no value for that path exists
path
(String | Array<String>) The sub-path within the project state to setvalue
any The value to setoptions
Object? Additional options to mutate behaviour, see setProjectState() for the full list of supported options
Returns Promise<Boolean> A promise which resolves to whether any changes were made - True if defaults were applied, false otherwise
Force copying local changes to the server This is only ever needed when saving large quantities of data that need to be immediately available
Returns Promise A promise which resolves when the operation has completed
Force refetching the remote project state into local This is only ever needed when saving large quantities of data that need to be immediately available
Returns Promise A promise which resolves when the operation has completed
Force-Save the currently active project state
Returns Promise A promise which resolves when the operation has completed
- See: setProjectState()
Overwrite the entire project state with a new object
You almost never want to use this function directly, see setProjectState(path, value)
for a nicer wrapper
newState
Object The new state to replace the current state with
Returns Promise A promise which resolves when the operation has completed
Apply a computed just-diff
patch to the current project state
Patch
Object to apply
Returns Promise A promise which resolves when the operation has completed
Subscribe to project state changes
This will dispatch an RPC call to the source object applyProjectStatePatchLocal()
function with the patch
If the above call fails the subscriber is assumed as dead and unsubscribed from the polling list
Returns Promise<Function> A promise which resolves when a subscription has been created, call the resulting function to unsubscribe
Data structure for a file filter
library
Boolean? Restrict to library files onlyfilename
String? CSV of @momsfriendlydevco/match expressions to filter the filename by (filenames are the basename sans extension)basename
String? CSV of @momsfriendlydevco/match expressions to filter the basename byext
String? CSV of @momsfriendlydevco/match expressions to filter the file extension by
Prompt the user to select a library to operate on
-
options
Object? Additional options to mutate behaviouroptions.title
String The title of the dialog to display (optional, default"Select a file"
)options.hint
(String | Array<String>)? Hints to identify the file to select in array order of preferenceoptions.save
Boolean Set to truthy if saving a new file, UI will adjust to allowing overwrite OR new file name input (optional, defaultfalse
)options.filters
FileFilters? Optional file filtersoptions.allowUpload
Boolean Allow uploading new files (optional, defaulttrue
)options.allowRefresh
Boolean Allow the user to manually refresh the file list (optional, defaulttrue
)options.allowDownloadZip
Boolean Allow the user to download a Zip of all files (optional, defaulttrue
)options.allowCancel
Boolean Allow cancelling the operation. Will throw'CANCEL'
as the promise rejection if acationed (optional, defaulttrue
)options.autoRequire
Boolean RunrequireProject()
automatically before continuing (optional, defaulttrue
)options.filter
FileFilters? Optional file filters
Returns Promise<ProjectFile> The eventually selected file, if in save mode new files are created as stubs
Remove a project file by its ID
id
String The File ID to remove
Returns Promise A promise which resolves when the operation has completed
Replace a project files contents
id
String File to overwritecontents
(File | Blob | FormData | Object | Array) The new file contents
Returns Promise A promise which will resolve when the write operation has completed
Prompt the user to select a library to operate on and return a array of references in a given format
-
options
Object? Additional options to mutate behaviouroptions.title
String The title of the dialog to display (optional, default"Select a citation library"
)options.hint
(String | Array<String>)? Hints to identify the library to select in array order of preference. Generally corresponds to the previous stage - e.g. 'deduped', 'review1', 'review2', 'dedisputed'options.allowUpload
Boolean Allow uploading new files (optional, defaulttrue
)options.allowRefresh
Boolean Allow the user to manually refresh the file list (optional, defaulttrue
)options.allowDownloadZip
Boolean Allow the user to download a Zip of all files (optional, defaulttrue
)options.allowCancel
Boolean Allow cancelling the operation. Will throw'CANCEL'
as the promise rejection if acationed (optional, defaulttrue
)options.autoRequire
Boolean RunrequireProject()
automatically before continuing (optional, defaulttrue
)options.filters
FileFilters? Optional file filters, defaults to citation library selection only
Returns Promise<Array<Ref>> A collection of references from the selected file
Fetch + convert a project file into a library of citations
-
id
String File ID to read -
options
Object? Additional options to mutate behaviouroptions.format
String Format for the file. ENUM: 'pojo' (return a parsed JS collection), 'blob' (raw JS Blob object), 'file' (named JS File object) (optional, default'json'
)options.autoRequire
Boolean RunrequireProject()
automatically before continuing (optional, defaulttrue
)options.filter
Function? Optional async file filter, called each time as(File:ProjectFile)
options.find
Function? Optional async final stage file filter to reduce all candidates down to one subject file
Returns (Promise<Array<Ref>> | Promise<any>) A collection of references (default bevahiour) or a whatever format was requested
Save back a citation library from some input
-
id
String? File ID to save back to, if omitted a file will be prompted for -
refs
(Array<RefLibRef> | Blob | File)? Collection of references for the selected library or the raw Blob/File -
options
Object? Additional options to mutate behaviouroptions.id
String? Alternate method to specify the file ID to save as, if omitted one will be prompted foroptions.refs
(Array<RefLibRef> | Blob | File)? Alternate method to specify the refs to save as an array or raw Blob/Fileoptions.format
String Input format used. ENUM: 'pojo' (return a parsed JS collection), 'blob' (raw JS Blob object), 'file' (named JS File object) (optional, default'json'
)options.autoRequire
Boolean RunrequireProject()
automatically before continuing (optional, defaulttrue
)options.hint
String? Hint to store against the library. Generally corresponds to the current operation being performed - e.g. 'deduped'options.filename
String? Suggested filename ifid
is unspecifiedoptions.title
String Dialog title ifid
is unspecified and a prompt is necessary (optional, default'Save citation library'
)options.overwrite
Boolean Allow existing file upsert (optional, defaulttrue
)options.meta
Object? Optional meta data to merge into the file data
Returns Promise A promise which resolves when the save operation has completed
Create a log entry for the currently active project
The required log object can be of various forms. See https://tera-tools.com/api/logs.json for the full list
log
Object The log entry to create
Returns Promise A promise which resolves when the operation has completed
Set an active tools URL so that it survives a refresh This only really makes a difference to tools within the tera-tools.com site where the tool is working as an embed
url
String The URL to restore on next refresh
Set the active page title This is usually called by a tool nested within the tera-tools.com embed
title
String The current page title
Display simple text within TERA
Returns Promise A promise which resolves when the alert has been dismissed
Display, update or dispose of windows for long running tasks All options are cumulative - i.e. they are merged with other options previously provided
-
options
(Object | Boolean)? Additional options to mutate behaviour, if boolean false{close: true}
is assumedoptions.title
String Window title, can only be set on the initial call (optional, default'TERA'
)options.body
String Window body text, can only be set on the initial call (optional, default''
)options.bodyHtml
Boolean Treat body text as HTML (optional, defaultfalse
)options.close
Boolean Close the existing dialog, if true the dialog is disposed and options reset (optional, defaultfalse
)options.text
String? The text of the task being conductedoptions.progress
Number? The current progress of the task being conducted, this is assumed to be a value less thanmaxProgress
options.maxProgress
Number? The maximum value that the progress can be
Returns Promise A promise which resolves when the dialog has been updated
Open a popup window containing a new site
-
url
String The URL to open -
options
Object? Additional options to mutate behaviouroptions.width
Number The desired width of the window (optional, default500
)options.height
Number The desired height of the window (optional, default600
)options.center
Boolean Attempt to center the window on the screen (optional, defaulttrue
)options.permissions
Object? Additional permissions to set on opening, defaults to a suitable set of permission for popups (see code)
Returns WindowProxy The opened window object (if noopener
is not set in permissions)
Display HTML content full-screen within TERA This function is ideally called within a requestFocus() wrapper